From the course: Modern CSS Techniques without JavaScript
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Switching from one color scheme to another without JavaScript
From the course: Modern CSS Techniques without JavaScript
Switching from one color scheme to another without JavaScript
- [Instructor] While users probably love having their preferred color scheme applied, other users may want the option to switch from one to the other. Historically, this has to be done with JavaScript. However, thanks to the light/dark function and the has() pseudo class, we can also set this up with radio buttons or similar options. So as you see here in this particular code pen, I have added some radio buttons for our color mode, light and dark. And if we take a look at the HTML, I've just given this to you here in the window rather than typing all of this in, we start with a fieldset. The fieldset is that line that goes around here and it's important to include this for accessibility reasons. So we're going to give this an ID of the mode-switcher, that's what this is. And then we're going to give it a legend, once again, what is happening inside of this field, important for accessibility. We're asking to select a color mode. In here, we've then set up two radio buttons. The first…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
What are light/dark color schemes?1m 49s
-
(Locked)
Setting up a color scheme with color-scheme3m 10s
-
(Locked)
Working with the CSS light-dark() function5m 34s
-
(Locked)
Switching from one color scheme to another without JavaScript7m 48s
-
(Locked)
Switching images to match color schemes with <picture>4m 22s
-
(Locked)
Challenge: Light/dark color schemes with SVGs3m 2s
-
(Locked)
Solution: Light/dark color schemes with SVGs2m 18s
-
(Locked)
-
-