Skip to: content, navigation

by Ian Lloyd

style (HTML attribute)

Spec
Depr. Version
No HTML 4
Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
style="css-property:css-value;…"

Example

If you want to set a paragraph to display in blue and bold, you could use the following code:

<p style="color:blue;font-weight:bold;">This is a very short
    paragraph. No Booker Prize for me.</p>

Description

In Cascading Style Sheets (CSS), a key feature is the cascade itself. In the cascade, styles set at different levels take different levels of importance, so a style that’s set in a globally linked style sheet can be overridden by a style for the same class or id that’s included in an embedded style sheet. The style attribute goes a level further, to override styles set in linked or embedded style sheets.

However, the use of the style attribute is generally considered to be a bad practice, as it causes the presentation to become intrinsically mixed with the content of the document—a practice that’s almost as bad as using the font element to style text. One way in which you might use inline styles is to debug CSS display issues (applying the style at its lowest level in the cascade, and progressively moving higher up the cascade until the problem is isolated). You should, therefore, avoid using inline style attributes in your markup.

Value

The style attribute includes a series of CSS property and value pairs. Each "property":"value" pair is separated by a semicolon, just as it is when it’s typed into an embedded or linked style sheet (although there should not be a carriage return after the semicolon when the pair is used inside the style attribute.

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

Compatibility issues depend heavily on each individual browser’s CSS rendering capabilities. All the browsers listed support the style attribute, and thus allow the addition of inline styles using the style attribute.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters