NOTICE: This website is no longer updated or supported - as such many of the techniques used to build it may seem antiquated in the modern day. It is preserved for historical reasons only.

HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<style> (Style Information)


This element is used to surround style sheet rules for a document. This element should be found only in the head element. Style rules within a document's <body> should be set with the style attribute for a particular element.

Standard Syntax


<style
dir="ltr | rtl"
id="unique alphanumeric string"
lang="language code"
media="all | print | screen | others"
title="advisory text"
type="MIME Type"
xml:space="preserve"
CSS properties
</style>

Common Attributes


disabled="disabled" (DOM Level 1)

Events Introduced by Internet Explorer


onerror, onreadystatechange

Element Specific Attributes


disabled
This Microsoft-defined attribute is used to disable a style sheet. The presence of the attribute is all that is required to disable the style sheet. In conjunction with scripting, this attribute could be used to turn on and off various style sheets in a document.

media
This attribute specifies the destination medium for the style information. The value of the attribute can be a single media descriptor like screen or a comma-separated list. Possible values for this attribute include all, aural, braille, print, projection, screen, and tv. Other values also might be defined, depending on the browser. Internet Explorer supports all, print, and screen as values for this attribute.

type
This attribute is used to define the type of style sheet. The value of the attribute should be the MIME type of the style sheet language used. The most common current value for this attribute is text/css, which indicates a Cascading Style Sheet format.

xml:space
This attribute is included from XHTML 1.0 and is used to specify whether spaces need to be preserved within the script element or whether the default white space handling should be employed. In practice, this attribute is not used by developers.

Example


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Style Sheet Example</title>

<style type="text/css">
<!--

  body  {background: black; color: white;
    font: 12pt Helvetica}
  h1    {color: red; font: 14pt Impact}
-->
</style>

</head>

<body>


<h1>A 14-point red Impact heading on a black
background</h1>

Regular body text, which is 12 point white Helvetica

</body>
</html>

Compatibility


HTML 4, 4.01, XHTML 1.0, 1.1
Netscape 4, 4.5-4.8, 6, 7
Internet Explorer 3, 4, 5, 5.5, 6
Opera 4-7

Notes


Style information also can be specified in external style sheets as defined by the <link> tag.

Style information can also be associated with a particular element using the style attribute.

Style rules are often commented out within a <style> tag to avoid interpretation by nonconforming browsers.
<style type="text/css">
<!--
   body {background-color: red;
-->
</style>

(X)HTML Elements
CSS Properties
Previous: strong Next: sub
< Home | About | Chapters | Examples | Errata | Reference | Site Map >