style (HTML attribute)
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
| IE | 5.5 | Full |
|---|---|---|
| 6.0 | Full | |
| 7.0 | Full | |
| Firefox | 1.0 | Full |
| 1.5 | Full | |
| 2.0 | Full | |
| Safari | 1.3 | Full |
| 2.0 | Full | |
| 3.0 | Full | |
| Opera | 9.2 | Full |
| 9.5 | 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
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.

