Please disable your ad blocker.

The only ads on this site are discreet (sidebar on desktop, below the content on mobile).
They do not interfere with reading and may even offer you benefits (discounts, free months…).

HTML/JS: create a button to change theme

Difficulty

This accessible tutorial will allow you to copy/paste the code and customize it according to your needs.

Feel free to modify the code directly here on breat.fr to see changes in real time. Even though your modifications won’t be saved, it’s the best way to experiment and understand how everything works!

The result shown below is not functional because it requires CSS files. However, if you place this code on your website and properly link your CSS files, it will work.

A button to switch from a light theme to a dark theme (or vice versa) is especially useful for improving accessibility on all websites. So, ready to create yours?