Inline styles refers to style rules that are placed inside an XHTML tag.
<div style="background : silver;"><p>Here is a block of text that will appear with a silver background in the browser, regardless of the background color of the page.</p></div>
Inline styles are great if you have an internal or external style sheet and just want to override the default style for a particular tag. Don't use them as your primary means of styling pages because they are tedious to maintain consistently across numerous pages. In this regard, inline styles are no better than the old <font> tag.
Type the code below into any text editor and save it with the name "csslesson02.html" in your "mySite" folder. You may view the completed lesson in a new window by clicking here . After you create this page, open it in your Web browser.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Lesson 2: Inline Styles</title>
</head>
<body bgcolor="white">
<h1>Welcome to Sidebars Anonymous</h1>
<p>This paragraph uses the default white background of the page.</p>
<div style="background : silver;"><p>Here is a block of text that will
appear with a silver background in the browser, regardless of the background color of
the page.</p></div>
</body>
</html>
The text within the document itself explains much. The style change for the <div> is indicated as an attribute within the tag itself. Use inline styles sparingly for special formatting needs.