style (HTML attribute)

Depr. Version
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Full Full Full Full




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.

Note that the style attribute cannot be applied to the following elements:

  • base
  • basefont
  • head
  • html
  • meta
  • param
  • script
  • style
  • title


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>


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.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Full Full Full Full Full Full Full Full Full Full Full

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

Related Products