HTML » Tags » style

Version: 3.2, 4.0

Compability: Explorer 4, 5  Netscape 4, 6

<style> ... </style>

The <style> tag is used to create document-level style sheet rules. It is referred to as document-level because the style rules will apply to the entire HTML page. In contrast, the style core attribute behaves as an inline style rule and only effects a small portion the HTML document.

The style tag must appear inside the head element. The code, contained between the opening and closing style tags, is not HTML, but is CSS (Cascading Style Sheets). The general concept is that a CSS property is assigned to a selector keyword, such as an HTML tag.
Unfortunately, not all browsers (especially older browsers) recognize this tag. It is recommended that you place an HTML opening comment tag right after the opening style tag and a closing comment tag immediately before the closing /style tag. A browser that recognizes CSS will ignore these comment tags and execute the code. Conversely, a browser that does not recognize CSS will treat the contents as simply a comment.
The closing tag is mandatory.


<style type="text/css">
br { font-face: arial; color: black; font-size: 12px" }
pre { font-face: arial; color: red; font-size: 18px" }
code { font-face: courier; color: blue; font-size: 15px" }

Here is a simple example of creating document-level style rules. A series of CSS properties defining font face, color, and size is assigned to the br, pre, and code tags. For more information about style sheets, please see the CSS2 Quick Reference.

Language(s): HTML

See Also: