Fireship · @fireship
CSS Theme Switcher by Reverse-Engineering Alligator.io
Uploaded March 25, 2020 · Length 13:54
Summary
Learn how to build a CSS theme switcher with variables and JavaScript, reverse-engineering Alligator.io's UI.
- css theme switcher
- alligator io
- css variables
- javascript
- ui design
- reverse engineering
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
one of my all-time favorite development
- 0:01
sites is alligator IO so naturally I
- 0:03
think we should reverse engineer some of
- 0:05
its UI like all good development sites
- 0:07
it gives us the option to switch between
- 0:09
a light and dark mode and it even goes a
- 0:10
step further to give us solarized themes
- 0:12
as well in today's video you'll learn
- 0:14
how to build a feature like this from
- 0:15
scratch using CSS variables and a little
- 0:18
bit of JavaScript and it's actually a
- 0:19
lot easier than you might think along
- 0:21
the way you'll also learn a bunch of
- 0:22
other cool things like how to create
- 0:23
this triangle shape with CSS how to
- 0:25
create a drop-down menu without
- 0:27
JavaScript and we'll finish up the video
- 0:29
by giving our logo this rainbow white
- 0:30
color transition when we hover over it
- 0:32
if you're new here like and subscribe
- 0:34
and grab the source code for this
- 0:35
project on fire ship IO or github let's
- 0:38
start by taking a closer look at what
- 0:39
we're building today we have a navbar
- 0:41
that's based on flexbox when you click
- 0:43
on themes it opens a drop-down and I'll
- 0:45
show you a cool technique for keeping
- 0:47
this drop-down open using nothing but
- 0:48
CSS so no JavaScript is required for the
- 0:51
dropdown itself but when you click a
- 0:53
button inside it does use JavaScript to
- 0:55
change the CSS variables in the page to
- 0:57
update the theme you'll notice we have
- 0:59
an option for light and dark mode and
- 1:01
then an option to Solarize which gives
- 1:03
us a variation on top of these producing
- 1:05
a total of four different color schemes
- 1:07
and you'll also notice that after I
- 1:08
select a theme and then refresh the page
- 1:10
that theme is still applied we do that
- 1:12
by caching the users selection in the
- 1:14
browser's local storage on top of that
- 1:16
we'll look at how we can control shapes
- 1:18
and CSS and I'll throw in a variety of
- 1:20
different animation techniques as well
- 1:21
before we get started I just want to
- 1:23
remind you that we move pretty quickly
- 1:25
on this channel so feel free to pause
- 1:26
the video or slow down the playback
- 1:28
speed and if you want to jump to a
- 1:30
specific feature check out the
- 1:31
timestamps in the video description in
- 1:33
our project we have files for HTML CSS
- 1:35
and JavaScript all of which are
- 1:37
currently empty let's start things off
- 1:39
in the HTML to give our website some
- 1:41
structure hit exclamation mark tab to
- 1:43
create the initial HTML boilerplate from
- 1:46
there I'm using a custom font that I got
- 1:47
from Google and I set up the style sheet
- 1:49
by typing link: CSS and hitting tab and
- 1:52
then I referenced our JavaScript by
- 1:54
typing script: source and hitting tab
- 1:56
then we'll point that to app J s and
- 1:58
we'll make sure to use the defer
- 1:59
attribute so the script loads after our


