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 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.

Have you published a response to this? :

Responses

Šime

Re adactio.com/journal/19365, the reason why Chrome and Safari load alternative stylesheets is probably because they don’t support them, so the “alternate” keyword means nothing to them and the stylesheets are treated as regular stylesheets.

# Posted by Šime on Thursday, December 8th, 2022 at 11:14pm

1 Bookmark

# Bookmarked by Zachary Dunn on Thursday, August 18th, 2022 at 12:09am

Related posts

Code print

Print stylesheets and QR codes: one great flavour and one yucky flavour that taste quite good together.

Switching

I’m using Firefox (for now).

Multi-page web apps

A question via email…

Get safe

It should be safe to visit a web page.

Accessible interactions

Abstracting common interaction patterns as a starting point for accessible components.

Related links

print-color-adjust - CSS: Cascading Style Sheets | MDN

I love print stylesheets but I was today years old when I found out that print-color-adjust exists.

Tagged with

User Stylesheets Are Still Pretty Great and Should Be More Widely Supported — Pixel Envy

Hear, hear!

If you have even a passing knowledge of CSS, I encourage you to experiment with its possibilities.

Tagged with

Oh No! Our Stylesheet Only Grows and Grows and Grows! (The Append-Only Stylesheet Problem) | CSS-Tricks

I think Chris is on to something here when he identifies one of the biggest issues with CSS growing out of control:

The developers are afraid of the CSS.

Tagged with

There are maps for these territories | Clearleft

A great piece from Danielle on the different mental models needed for different languages. When someone describes a language—like CSS—as “broken”, it may well be that there’s a mismatch in mental models.

CSS isn’t a programming language. It’s a stylesheet language. We shouldn’t expect it to behave like a programming language. It has its own unique landscape and structures, ones that people with programming language mental maps might not expect.

I believe that this mismatch of expectation is what has led to the current explosion of CSS-in-JS solutions. Confronted with a language that seems arbitrary and illogical, and having spent little or no time exposed to the landscape, developers dismiss CSS as ‘broken’ and use systems that either sweep it under the rug, or attempt to force it into alignment with the landscape of a programming language — often sacrificing some of the most powerful features of CSS.

Tagged with

Base64 Encoding & Performance, Part 1: What’s Up with Base64?

Harry clearly outlines the performance problems of Base64 encoding images in stylesheets. He’s got a follow-up post with sample data.

Tagged with

Previously on this day

3 years ago I wrote Upgrade paths

If you’re going to deprecate a feature on the web, at least give us an alternative.

11 years ago I wrote August in America, day thirteen

San Diego, California.

13 years ago I wrote Re-tabulate

Combining responsive design with CSS table layout to rearrange the display of content and navigation.

13 years ago I wrote Re-flex

Putting content first by combining responsive design with the CSS3 flexible box layout module.

17 years ago I wrote Wireframework

Frameworks have their place… but that place probably isn’t on the Web.

18 years ago I wrote API changes

Heads up. Flickr and Del.icio.us have made some changes.

19 years ago I wrote Joe Clark in the flesh

Ryan Carson, one of the minds behind BD4D, has started putting on some pretty darn excellent one-day workshops in London. He’s already had Eric Meyer over for CSS training. Next week, Cal Henderson will be talking about the building of Flickr.

19 years ago I wrote Blogging from Word

In April 2004, Tim Bray wrote:

20 years ago I wrote A gaggle of geeks

This weekend, Brighton was the setting for Geekend 2: Electric Boogaloo.

21 years ago I wrote Swimming

Swimming is just like riding a bike: life-threateningly dangerous but good exercise.

22 years ago I wrote Betrayal

Take a look at the photo in this PR story from the White House.