How to disable a CSS stylesheet with JavaScript

On September 27, 2022 by Sosthène Guédon

Listen to this article
00:00 _:_ 50%

Contrary to what every website out there is saying, the proper way to disable a remote stylesheet imported with <link rel="stylesheet" type="text/css" href="/url"> is not to use stylesheet.disabled = true;, it's rather to use stylesheet.media = "not all";. Using disabled on <link> element is not standard and should be avoided. It doesn't seem to even work properly in chrome.

This feels like a hack but it's the only way I've found that seems to work on both Firefox and Chromium. It powers the theme switcher on this website.