Inline Styles
In HTML and XHTML, style information can be specified for an individual element via the style
attribute. The value of a style
attribute is a declaration block (see the upcoming section "Rule Structure“) without the curly braces:
<p style="color: red; background: yellow;">Look out! This text is alarmingly presented!</p>
Note that, as of this writing, a full style sheet cannot be placed into a style
attribute. Only the content of a single declaration block can be used as a style
attribute value. For example, it is not possible to place hover styles (using :hover
) in a style
attribute, nor can one use @import
in this context.
Although typical XML document languages (e.g., XHTML 1.0, XHTML 1.1, and SVG) support the style
attribute, it is unlikely that all XML languages will support a similar capability. Due to this and the fact that it encourages poor authoring practices, authors are generally discouraged from using the style
attribute.
Get CSS Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.