rel="alternate stylesheet"
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thealternate stylesheet
keyword pair, when used as a value for therel
attribute of the<link>
element, indicates that the target resource is analternative style sheet. Specifyingalternative style sheets in a web page allows users to see multiple versions of a page based on their needs or preferences.
Note:This feature is not well supported in browsers without an extension. To offer alternative presentations that work with a user's existing preferences, see the CSSmedia featuresprefers-color-scheme
andprefers-contrast
.
Firefox lets users select alternatestylesheets using theView > Page Style submenu, which displays the values of thetitle
attributes. Other browsers require an extension to enable this functionality. The web page can also provide its own user interface to let users switch styles.
Examples
Specifying alternate stylesheets
Alternate stylesheets are specified using<link>
elements withrel="alternate stylesheet"
andtitle="…"
attributes. For example:
<link href="reset.css" rel="stylesheet" /><link href="default.css" rel="stylesheet" title="Default Style" /><link href="fancy.css" rel="alternate stylesheet" title="Fancy" /><link href="basic.css" rel="alternate stylesheet" title="Basic" />
In this example, the styles "Default Style", "Fancy", and "Basic" will be listed in the FirefoxPage Style submenu with "Default Style" pre-selected. When the user selects a different style, the page will immediately be re-rendered using that style sheet.
No matter what style is selected, the rules from thereset.css
stylesheet will always be applied.
Try it out
Details
Any stylesheet in a document falls into one of the following categories:
- Persistent (has
rel="stylesheet"
, notitle=""
): always applies to the document. - Preferred (has
rel="stylesheet"
, withtitle="…"
specified): applied by default, butdisabled if an alternate stylesheet is selected.There can only be one preferred stylesheet, so providing stylesheets with different title attributes will cause some of them to be ignored. - Alternate (
rel="alternate stylesheet"
, withtitle="…"
specified): disabled by default, can be selected.
In cases where a stylesheet menu exists, when style sheets are referenced with atitle
attribute on the<link rel="stylesheet"> or<style>
element, the title becomes one of the choices offered to the user. Style sheets linked with the sametitle
are part of the same choice. Style sheets linked without atitle
attribute are always applied.
Userel="stylesheet"
to link to the default style, andrel="alternate stylesheet"
to link to alternative style sheets. This tells the browser which style sheet title should be selected by default, and makes that default selection apply in browsers that do not support alternate style sheets.
Specifications
Specification |
---|
HTML # rel-alternate |
HTML # the-link-is-an-alternative-stylesheet |
HTML # attr-style-title |
HTML # attr-meta-http-equiv-default-style |
CSS Object Model (CSSOM) # css-style-sheet-collections |