Contents
This section is normative.
The Style Sheet Module defines an element to be used when declaring internal style sheets. The element and attributes defined by this module are:
Elements | Attributes | Content Model |
---|---|---|
style | Common, disabled ("disabled"), media (MediaDesc) | PCDATA |
Implementation: RELAX NG
Attributes
access
element is intended.
When the value of this attribute matches the current processing media,
the associated access
element is
considered active and processed normally; otherwise it is
inactive and ignored.
The default value for this attribute is all
.
Example
<style src="style.css" type="text/css" media="screen" /> <span src="photo.jpg" media="screen">Me at work</span> <span src="photo-hires.jpg" media="print">Me at work</span>
The style element allows an author to put style sheet rules in the head of the document. XHTML permits any number of style elements in the head section of a document.
The syntax of style data depends on the style sheet language.
Rules for style rule precedences and inheritance depend on the style sheet language.
Example
<style type="text/css"> h1 {border-width: thin; border-style: solid; text-align: center} </style>
Authors may separate style sheets from XHTML documents. This offers several benefits:
XHTML allows authors to associate any number of external style sheets with a document. The style sheet language defines how multiple external style sheets interact (for example, the CSS "cascade" rules).
Authors may specify a number of mutually exclusive style sheets called alternate style sheets. Users may select their favorite among these depending on their preferences. For instance, an author may specify one style sheet designed for small screens and another for users with weak vision (e.g., large fonts). User agents should allow users to select from alternate style sheets.
The author may specify that one of the alternates is a preferred style sheet. User agents should apply the author's preferred style sheet unless the user has selected a different alternate.
Authors may group several alternate style sheets (including the author's preferred style sheets) under a single style name. When a user selects a named style, the user agent must apply all style sheets with that name. User agents must not apply alternate style sheets with a different style name. The section on specifying external style sheets explains how to name a group of style sheets.
User agents must respect media descriptors when applying any style sheet.
User agents should also allow users to disable the author's style sheets entirely, in which case the user agent must not apply any persistent or alternate style sheets.
Authors specify external style sheets using the xml-stylesheet
processing instruction [XMLSTYLE], or, for CSS, by using the @import
facility within a
style element.
User agents should provide a means for users to view and pick from the list of alternate styles, if specified.
In this example, we first specify a persistent style sheet located in the file mystyle.css:
Example
<?xml-stylesheet href="mystyle.css" type="text/css"?>
Setting the title
pseudo-attribute makes this the author's preferred style sheet:
Example
<?xml-stylesheet href="mystyle.css" title="compact" type="text/css"?>
Adding the alternate
pseudo-attribute makes it an alternate style sheet:
Example
<?xml-stylesheet href="mystyle.css" title="Medium" alternate="yes" type="text/css"?>