Alternative stylesheets

My website has different themes you can choose from. I don’t just mean a dark mode. These themes all look very different from one another.

I assume that 99.99% of people just see the default theme, but I keep the others around anyway. Offering diffe…


This content originally appeared on Adactio: Journal and was authored by Adactio: Journal

My website has different themes you can choose from. I don’t just mean a dark mode. These themes all look very different from one another.

I assume that 99.99% of people just see the default theme, but I keep the others around anyway. Offering different themes was originally intended as a way of showcasing the power of CSS, and specifically the separation of concerns between structure and presentation. I started doing this before the CSS Zen Garden was created. Dave really took it to the next level by showing how the same HTML document could be styled in an infinite number of ways.

Each theme has its own stylesheet. I’ve got a very simple little style switcher on every page of my site. Selecting a different theme triggers a page refresh with the new styles applied and sets a cookie to remember your preference.

I also list out the available stylesheets in the head of every page using link elements that have rel values of alternate and stylesheet together. Each link element also has a title attribute with the name of the theme. That’s the standard way to specify alternative stylesheets.

In Firefox you can switch between the specified stylesheets from the View menu by selecting Page Style (notice that there’s also a No style option—very handy for checking your document structure).

Other browsers like Chrome and Safari don’t do anything with the alternative stylesheets. But they don’t ignore them.

Every browser makes a network request for each alternative stylesheet. The request is non-blocking and seems to be low priority, which is good, but I’m somewhat perplexed by the network request being made at all.

I get why Firefox is requesting those stylesheets. It’s similar to requesting a print stylesheet. Even if the network were to drop, you still want those styles available to the user.

But I can’t think of any reason why Chrome or Safari would download the alternative stylesheets.


This content originally appeared on Adactio: Journal and was authored by Adactio: Journal


Print Share Comment Cite Upload Translate Updates
APA

Adactio: Journal | Sciencx (2022-08-16T10:36:44+00:00) Alternative stylesheets. Retrieved from https://www.scien.cx/2022/08/16/alternative-stylesheets/

MLA
" » Alternative stylesheets." Adactio: Journal | Sciencx - Tuesday August 16, 2022, https://www.scien.cx/2022/08/16/alternative-stylesheets/
HARVARD
Adactio: Journal | Sciencx Tuesday August 16, 2022 » Alternative stylesheets., viewed ,<https://www.scien.cx/2022/08/16/alternative-stylesheets/>
VANCOUVER
Adactio: Journal | Sciencx - » Alternative stylesheets. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/08/16/alternative-stylesheets/
CHICAGO
" » Alternative stylesheets." Adactio: Journal | Sciencx - Accessed . https://www.scien.cx/2022/08/16/alternative-stylesheets/
IEEE
" » Alternative stylesheets." Adactio: Journal | Sciencx [Online]. Available: https://www.scien.cx/2022/08/16/alternative-stylesheets/. [Accessed: ]
rf:citation
» Alternative stylesheets | Adactio: Journal | Sciencx | https://www.scien.cx/2022/08/16/alternative-stylesheets/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.