Yogesh Chauhan's Blog

Alternate Style Sheets in CSS

in CSS on February 4, 2021

We usually add one stylesheet to out HTML code but an HTML document doesn’t need to have a single style sheet.

We can have a default style for the HTML page and any number of alternatives stylesheets for the reader to choose from.

Why to use it?

It provides few options for users to choose from. Users can select any version of a page, based on their preferences.

The browser decided on which alternatives styles the reader can choose and not every browsers or version of browsers supports it but many of them do.

In Opera and Firefox we can find the styles under the “View” menu. Chrome versions 1-48 don’t support it at all but we can add an extension to it to make it support the alternate stylesheets. Checkout the compatibility report on MDN.

Here is the screen capture from Mozilla.

Alternate stylesheets in Mozilla

To include extra style sheets, we need to add more LINK tags in the header, with the correct REL and TITLE attributes.

Examples

In the example above, the first stylesheet “main.css” will be applied to the HTML page no matter what.

From next 3 listed stylesheets, style_1 will be on the default selected in the browser menu. User can select any stylesheet from those 3 styles.

Sources


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
The basics of CSS Box modelCSSGap in Flex?CSSHow to get ACF values from custom post type?WordPressapply_filters function in WordPressWordPressThe SQL UNION OperatorSQL/MySQLUse SwiperJS to create mobile touch sliders fastMiscellaneous