Fireship · @fireship

CSS Theme Switcher by Reverse-Engineering Alligator.io

Uploaded March 25, 2020 · Length 13:54

CSS Theme Switcher by Reverse-Engineering Alligator.io

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.

  1. 0:00

    one of my all-time favorite development

  2. 0:01

    sites is alligator IO so naturally I

  3. 0:03

    think we should reverse engineer some of

  4. 0:05

    its UI like all good development sites

  5. 0:07

    it gives us the option to switch between

  6. 0:09

    a light and dark mode and it even goes a

  7. 0:10

    step further to give us solarized themes

  8. 0:12

    as well in today's video you'll learn

  9. 0:14

    how to build a feature like this from

  10. 0:15

    scratch using CSS variables and a little

  11. 0:18

    bit of JavaScript and it's actually a

  12. 0:19

    lot easier than you might think along

  13. 0:21

    the way you'll also learn a bunch of

  14. 0:22

    other cool things like how to create

  15. 0:23

    this triangle shape with CSS how to

  16. 0:25

    create a drop-down menu without

  17. 0:27

    JavaScript and we'll finish up the video

  18. 0:29

    by giving our logo this rainbow white

  19. 0:30

    color transition when we hover over it

  20. 0:32

    if you're new here like and subscribe

  21. 0:34

    and grab the source code for this

  22. 0:35

    project on fire ship IO or github let's

  23. 0:38

    start by taking a closer look at what

  24. 0:39

    we're building today we have a navbar

  25. 0:41

    that's based on flexbox when you click

  26. 0:43

    on themes it opens a drop-down and I'll

  27. 0:45

    show you a cool technique for keeping

  28. 0:47

    this drop-down open using nothing but

  29. 0:48

    CSS so no JavaScript is required for the

  30. 0:51

    dropdown itself but when you click a

  31. 0:53

    button inside it does use JavaScript to

  32. 0:55

    change the CSS variables in the page to

  33. 0:57

    update the theme you'll notice we have

  34. 0:59

    an option for light and dark mode and

  35. 1:01

    then an option to Solarize which gives

  36. 1:03

    us a variation on top of these producing

  37. 1:05

    a total of four different color schemes

  38. 1:07

    and you'll also notice that after I

  39. 1:08

    select a theme and then refresh the page

  40. 1:10

    that theme is still applied we do that

  41. 1:12

    by caching the users selection in the

  42. 1:14

    browser's local storage on top of that

  43. 1:16

    we'll look at how we can control shapes

  44. 1:18

    and CSS and I'll throw in a variety of

  45. 1:20

    different animation techniques as well

  46. 1:21

    before we get started I just want to

  47. 1:23

    remind you that we move pretty quickly

  48. 1:25

    on this channel so feel free to pause

  49. 1:26

    the video or slow down the playback

  50. 1:28

    speed and if you want to jump to a

  51. 1:30

    specific feature check out the

  52. 1:31

    timestamps in the video description in

  53. 1:33

    our project we have files for HTML CSS

  54. 1:35

    and JavaScript all of which are

  55. 1:37

    currently empty let's start things off

  56. 1:39

    in the HTML to give our website some

  57. 1:41

    structure hit exclamation mark tab to

  58. 1:43

    create the initial HTML boilerplate from

  59. 1:46

    there I'm using a custom font that I got

  60. 1:47

    from Google and I set up the style sheet

  61. 1:49

    by typing link: CSS and hitting tab and

  62. 1:52

    then I referenced our JavaScript by

  63. 1:54

    typing script: source and hitting tab

  64. 1:56

    then we'll point that to app J s and

  65. 1:58

    we'll make sure to use the defer

  66. 1:59

    attribute so the script loads after our