W3C

Bert Bos | CSS tutorial – style attribute

CSS style attributes

CSS style attributes

The normal way to use CSS is to put the style rules in one or more files and link the files from all documents they apply to. This allows easy re-use of style sheets, changing the style without touching the document, and normally uses the least bandwidth.

(The next slides will explain more about the media attribute.)

The <link> element exists in HTML and SVG. For generic XML there is an equivalent “processing instruction.”

Occasionally, a single document needs some overrides, and then the <style> element is handy.

CSS also specifies the syntax of the style attribute of HTML, SVG and MathML.

A style attribute has a much more limited syntax than a CSS file or a <style> element. It can occasionally be useful for debugging, or it may be used by a system that allows elements to be copied and pasted.

In general, if you find yourself using style attributes other than for testing, you should ask yourself if you didn't make a mistake in the structure of your documents and style sheets.