Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Specifying Inline Styles

In some situations, you might want to specify styles that will be used in only one Web page. You can then enclose a style sheet between <style> and </style> tags and include it in the beginning of an HTML document, between the </head> and <body> tags. No <link /> tag is needed, and you cannot refer to that style sheet from any other page (unless you copy it into the beginning of that document, too).

If you want to specify a style for only a small part of a page, you can go one step further and put a style attribute within a <p>, <div>, or <span> tag.

Here's how a sample style attribute might look:

<p style="color: green">This text is green, but
<span style="color: red"> this text is red.</span>
Back to green again, but…</p>
<p>…now the green is over, and we're back to the default color for
this page.</p>

Although the effect of this example could be achieved as easily with the <font color> tag (see Hour 6, "Text Formatting and Font Control" ), many style specifications have no corresponding HTML tag. Generally, you should avoid inline styles except when there is no way to do what you're after in HTML and you feel that using an external style sheet would be too cumbersome.

Share ThisShare This

Informit Network