How To Build An Advanced Light/Dark Theme Toggle

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.พ. 2020
  • Theme toggles are a fairly simple concept, so in this video I decided to take a theme toggle to the next level by creating animations around the theme switch. These animations lead to a really fun project that covers CSS custom properties, CSS specificity and so much more.
    📚 Materials/References:
    GitHub Code: github.com/WebDevSimplified/A...
    CodePen Code: codepen.io/WebDevSimplified/p...
    Emmet Tutorial: • Learn Emmet In 15 Minu...
    Material Design Icons: materialdesignicons.com/
    🧠 Concepts Covered:
    - How to use CSS custom properties
    - How to handle CSS transitions
    - CSS position context
    - Managing document overflow
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #ThemeToggle #WDS #LightDarkMode

ความคิดเห็น • 95

  • @3FatesLive
    @3FatesLive 4 ปีที่แล้ว +43

    me: I wonder how to make a dark theme toggle
    webdevsimplified: I read minds

  • @slavoie
    @slavoie 4 ปีที่แล้ว +15

    Fantastic content and very clean presentation style! I love how you explain everything along the way so clearly and effortlessly: even as a beginner, I had no problem following thanks to you showing what was happening at every step. Well done!

  • @ScileSc
    @ScileSc 4 ปีที่แล้ว +24

    Dude I was just thinking about that and here you go reading my mind.

  • @greatblaise
    @greatblaise 4 ปีที่แล้ว +1

    Wow man. You really know your stuff. It's impressive how confidently you take us through the project. I definitely know what channel I'm coming to for web dev. Good stuff!

  • @DavetheTrainer
    @DavetheTrainer 4 ปีที่แล้ว +1

    One of the best tutorials I've seen - amazing work Kyle!

  • @user-yw4wc2fy3u
    @user-yw4wc2fy3u 11 หลายเดือนก่อน +1

    I always used to use this approach of CSS variables, but I wasn't sure if I was doing that right now all my self-doubts are cleared, Thank you so much

  • @shiytp
    @shiytp 4 ปีที่แล้ว +5

    only thing i didn't know about in this tutorial was vmin. i watch your videos because they are relaxing and i accidentally learned something on the way. great stuff.

  • @Almarexwebdev
    @Almarexwebdev 2 ปีที่แล้ว

    This is a life saver tutorial for me This morning.. I have been working on a project and the CSS variables was so confusing to manipulate between dark and light mode. I had to re-declare the CSS elements again and assign it to another value without using CSS variables... I know that's a double work. but after I watched this tutorial, I perfectly understood how to use CSS variables to manipulate between light and dark theme easily... Thanks man

  • @Berkeli
    @Berkeli 3 ปีที่แล้ว

    This is so good!!! I appreciate your guides, really easy to understand & follow.

  • @aimaneqbal
    @aimaneqbal 3 ปีที่แล้ว

    This is the most underrated video on this topic. This needs more reach

  • @jthomasaurus
    @jthomasaurus 4 ปีที่แล้ว +3

    I’ve watched you for over a year, and I’ve been coding for a little longer than that. Yet, you mentioned using defer as an alternative to putting the script at the end of the body.
    Although I understand both, I’ve never really connected the two honestly, but that’s what I love about your method of teaching, you go over every line basically and even the “small” stuff gets mentioned. You don’t explain only how, you explain how and WHY. And that’s really important to me. Also why I bought your CSS course! Keep it up! 👍🏼

  • @user-mg3ok3tv1e
    @user-mg3ok3tv1e 4 ปีที่แล้ว

    You are the best! Thank you for the tutorial!!!

  • @gillbates9668
    @gillbates9668 2 ปีที่แล้ว

    thanks for this tutorial! very informative

  • @leobailly1249
    @leobailly1249 2 ปีที่แล้ว

    Thanks ! Learned a lot ♥️

  • @smokvin
    @smokvin 4 ปีที่แล้ว

    Thank you!
    You deserve more likes!

  • @arnav_0397
    @arnav_0397 3 ปีที่แล้ว

    tons of appreciation is even not enough to appreciate you!

  • @smcalpha
    @smcalpha 4 ปีที่แล้ว

    Nicely explained!

  • @Star-zf8su
    @Star-zf8su 4 ปีที่แล้ว

    Thanks it helped me learn new properties 😍😍

  • @salih-khan
    @salih-khan 4 ปีที่แล้ว +1

    i just love watching your videos and i just love your contents
    i find you inspiring truly

  • @usama57926
    @usama57926 4 ปีที่แล้ว +1

    amazing tutorial

  • @hasanali6798
    @hasanali6798 4 ปีที่แล้ว

    hey man i love your work im doing this rn.

  • @samaritan5744
    @samaritan5744 4 ปีที่แล้ว

    Nice work!

  • @azatecas
    @azatecas 4 ปีที่แล้ว

    Great tutorial

  • @kallee7284
    @kallee7284 4 ปีที่แล้ว

    Nice video! I’m just wondering why you didn’t mention the @media prefers color scheme tag in this video. Maybe you can show how to make it automatically change to dark if the user has dark mode on.

  • @usama57926
    @usama57926 4 ปีที่แล้ว +1

    thank u so much sir it's helped a lot....................

  • @samsalem6927
    @samsalem6927 2 ปีที่แล้ว

    amazing, thank you

  • @ssukhvant
    @ssukhvant 3 ปีที่แล้ว

    Amazing video

  • @Maxtasy888
    @Maxtasy888 4 ปีที่แล้ว +1

    It works well in Google Chrome, but for some reason the color transition on the sun/moon doesn't work in the latest Firefox.

  • @dimitridoroshko
    @dimitridoroshko 4 ปีที่แล้ว

    Holy smokes! Kyle's uploaded a new video. Thanks so much! I've heard you got a job, can you share some info like what your position is and what your stack of technologies is.

    • @WebDevSimplified
      @WebDevSimplified  4 ปีที่แล้ว +2

      I have had my job for quite awhile now. I work mostly with Ruby on Rails with Postgres and React as my stack at work. I am a fullstack developer at my job.

    • @dimitridoroshko
      @dimitridoroshko 4 ปีที่แล้ว

      @@WebDevSimplified sounds fun. Do you find your job challenging and difficult?

  • @raoulkhaleb7258
    @raoulkhaleb7258 3 ปีที่แล้ว +2

    0:00 your mind is my ware house theme intro.

  • @travelingvibes7796
    @travelingvibes7796 4 ปีที่แล้ว

    Hi bro ,, I love your all js video you really simplify it can you make a video on carouseller please

  • @mounir101
    @mounir101 4 ปีที่แล้ว +1

    A new visitor hits the subscribe button. Thanks so much.

  • @fabiof.deaquino4731
    @fabiof.deaquino4731 4 ปีที่แล้ว

    Thanks! :)

  • @tonyzhao7915
    @tonyzhao7915 4 ปีที่แล้ว +1

    Great video, except your head was covering the moon the entire time before you added rotation lol. 21:50

  • @rahuljoshi8331
    @rahuljoshi8331 3 ปีที่แล้ว

    Sir due to the Inline style in Sun and Moon icon we were not able to change the height and width to 30px. I have suggested the changes in your Github please see to it. As it is my First pull req

  • @Maldito011316
    @Maldito011316 2 ปีที่แล้ว

    How do you load it automatically then?

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 3 ปีที่แล้ว

    If I want save the state for toggle then how can I do this?

  • @davidjustice2323
    @davidjustice2323 4 ปีที่แล้ว

    I love you!

  • @kemal_ozturk
    @kemal_ozturk 4 ปีที่แล้ว

    Hey Kyle, I often find myself using shitf+alt+f to auto indent whenever I change scopes. Is there a reason you are not using that in this video?
    Thanks for the helpful tuts bwt :)

    • @WebDevSimplified
      @WebDevSimplified  4 ปีที่แล้ว

      I find the auto formatted tends to mess things up in HTML.

  • @wassimbelhadjrhouma7979
    @wassimbelhadjrhouma7979 4 ปีที่แล้ว +3

    I like the video before watching it 😍😍

  • @rahulxdd
    @rahulxdd 3 ปีที่แล้ว

    why no semicolons in the JS code?
    Edit: Just found out the semicolons are optional but recommended in JS.

  • @rahuljoshi8331
    @rahuljoshi8331 3 ปีที่แล้ว

    why my moon and sun icons color not changing to white in dark mode

  • @theretroman3862
    @theretroman3862 2 ปีที่แล้ว

    Kyle my friend, I can see it in your eyes, you are super tired. As much as I like your videos and the frequency to which you are pumping them out, I am recommending a long vacation.
    There is no point stressing it out, we'll still be around here when you'll be back. One of my buddies died at 30 years old from cardio arrest, same deal, long hours, less sleep, over tired, trying to look at his best, it costed his life... just saying... take care my good man!

  • @shimphillip
    @shimphillip 4 ปีที่แล้ว

    Thanks for the video! What's the point of using calc?

    • @ItsSunnyMonster
      @ItsSunnyMonster 3 ปีที่แล้ว

      In css you have to use calc() to do calculations.

  • @brandoncbh
    @brandoncbh ปีที่แล้ว

    How about with React?

  • @wallijacanero1532
    @wallijacanero1532 3 ปีที่แล้ว

    Thank you very much for this video, I really needed your instructions to create the dark version of my website! I just have one question tho: even If I copied the codes showed, when I open the preview of the page It shows immediately body.dark theme and not the "standard", "white" one. How is that? It's not such a big problem, I just could invert the colors and I would make it anyway work as I want, but I would like to understand better this mechanic

    • @nedaltrebor8553
      @nedaltrebor8553 3 ปีที่แล้ว +1

      probably an issue with the javascript portion, removing the "dark" class from the body element.

    • @wallijacanero1532
      @wallijacanero1532 3 ปีที่แล้ว

      @@nedaltrebor8553 It was that!!! Thank you!!!

  • @gopalloharnew5948
    @gopalloharnew5948 2 ปีที่แล้ว +1

    _6:00_ *Keep your friends rich and your enemies rich, and wait to find out which is which*

    • @gopalloharnew5948
      @gopalloharnew5948 2 ปีที่แล้ว

      It's was said by Ultron but a man there says tony said this and I've read somewhere that Howard Stark said this!

  • @rudestewing
    @rudestewing 3 ปีที่แล้ว

    thank's

  • @vikasvk_
    @vikasvk_ 3 ปีที่แล้ว

    I tried transition for smooth toggle of bg color, but when its in dark mode and I refresh my page, I get a white flash and then it goes to dark mode. Is there a fix for this?

    • @arnav_0397
      @arnav_0397 3 ปีที่แล้ว

      set transition delay for that then it will took time to things happen and flash 'll appear

  • @xiaolong9446
    @xiaolong9446 3 ปีที่แล้ว

    Amazing lecture.

  • @leonardorocca712
    @leonardorocca712 3 ปีที่แล้ว

    Nice, how can I save the state of the toggle?

    • @psilocybin-
      @psilocybin- ปีที่แล้ว

      I use LocalStorage

  • @ipeach7278
    @ipeach7278 4 ปีที่แล้ว

    Thumb Up

  • @brandonreid7008
    @brandonreid7008 2 ปีที่แล้ว

    For some stange reason I followed every single step and double checked and still neither the sun nor the moon rotates. Only the accent changes, can you help me?

  • @superJerrySong
    @superJerrySong 3 ปีที่แล้ว

    men, how can i make a commentary so fast in HTML? how i use emmet to make a comment like you do?

  • @aminekarboul6363
    @aminekarboul6363 4 ปีที่แล้ว

    how can you see the outcome of the result without refreshing the page?

    • @csablons
      @csablons 4 ปีที่แล้ว +1

      He use a Visual Code plugin named "Live Server". Once installed you do a right click on your index.html file, choose "Open with Live Server" and that's all. Be sure to work with your file open in a folder with Visual Code.

  • @receiverreceiver1465
    @receiverreceiver1465 4 ปีที่แล้ว +1

    I like that .can you make it in react js with component thanks

  • @meansnada
    @meansnada 4 ปีที่แล้ว

    Great video :) I always wanted to know a more in depth way of doing this without using a library like say Angular Material, thank you :)
    One question tho, wouldn't this cause a bit of overload if say someone clicked that button a gazillion times? since the --rotation variable would be just adding 180 every time you click it. Just wondering.

    • @dimitridoroshko
      @dimitridoroshko 4 ปีที่แล้ว +1

      That's exactly what I was thinking. High five to my man!

    • @WebDevSimplified
      @WebDevSimplified  4 ปีที่แล้ว +1

      You shouldn't run into any issues with the rotation since even if the number gets big it would require an immense number of clicks before the number got too large.

  • @user-zp1dv4yh5e
    @user-zp1dv4yh5e 4 ปีที่แล้ว

    i got a JS problem "Cannot read property 'addEventListener' of null" , anyone can help !!

    • @travelingvibes7796
      @travelingvibes7796 4 ปีที่แล้ว

      What is the problem can you share the code

    • @user-zp1dv4yh5e
      @user-zp1dv4yh5e 4 ปีที่แล้ว

      @@travelingvibes7796
      const sunMoonContainer = document.querySelector('.sun-moon-container')
      var x=document.querySelector('.theme-toggle-button');
      window.onload=function() {
      x.addEventListener('click', () => {
      document.body.classList.toggle('dark');
      const currentRotation = parseInt(getComputedStyle(sunMoonContainer).getPropertyValue('--rotation'))
      sunMoonContainer.style.setProperty('--rotation', currentRotation + 180)
      });
      }
      ERROR :
      sc.js:13 Uncaught TypeError: Cannot read property 'addEventListener' of null
      at window.onload (sc.js:13)

    • @ahmadmuslih
      @ahmadmuslih 4 ปีที่แล้ว

      @@user-zp1dv4yh5e maybe you have typo in the html file for theme-toggle-button

    • @panos1984
      @panos1984 4 ปีที่แล้ว

      Make sure you have the attribute "defer" in the tag (in the HTML's section).
      ex.
      That way JS runs after the page has loaded and the element you want to select exists in the DOM.

  • @ItzSlacks
    @ItzSlacks 6 หลายเดือนก่อน

    I dont want that animation i want a button which switches !But cool tutorial

  • @sm1ley732
    @sm1ley732 4 ปีที่แล้ว +1

    i promise it is there xddd :D

  • @osamudiamenazamegbe5337
    @osamudiamenazamegbe5337 4 ปีที่แล้ว

    my transition isn't working, it still switches instantly 😥

    • @osamudiamenazamegbe5337
      @osamudiamenazamegbe5337 4 ปีที่แล้ว

      I fixed it. I use chrome so I needed to include: -webkit-transition: var(--transition-delay).

  • @WebDevdai
    @WebDevdai 4 ปีที่แล้ว

    nice boy

  • @user-zp1dv4yh5e
    @user-zp1dv4yh5e 4 ปีที่แล้ว

    bro, can you make a video, for interacting with OMDb API?

  • @tomvalusek
    @tomvalusek 4 ปีที่แล้ว

    I'm nostalgically remembering Windows 3.1, where I could create my own "dark mode" including buttons, scrollbars, etc. Such ability was taken from us, users, including user CSS's with !important rules, and we're at mercy of developers, which sucks

  • @OperationAndrew.
    @OperationAndrew. 4 ปีที่แล้ว +2

    Can I make a suggestion: make a really long video that breaks down the basics of a language start to finish. Will be a pain to make - but will bring all the beginners to your channel, who will then stay for the more advanced videos like this

    • @OperationAndrew.
      @OperationAndrew. 4 ปีที่แล้ว

      like you did for free code camp regarding css / html

  • @eduardmorarus
    @eduardmorarus 3 ปีที่แล้ว

    what's the hotkey he is using when fixing the indentation? where can I find another useful hotkeys like that one?

  • @ImTheDot
    @ImTheDot ปีที่แล้ว

    🌓

  • @SauravKumar-pq8bo
    @SauravKumar-pq8bo 3 ปีที่แล้ว +1

    i have a quetion... once i tried to add an icon in my web project but unable to find it online so i decided to make a svg in illustrator and when i use that svg in my page it didnt act like a icon (as i cant change its color) ...plss explain what to do in that case??

  • @mikethegamedev
    @mikethegamedev 3 ปีที่แล้ว

    Can i code like this on Mobile?

  • @onemorestory1
    @onemorestory1 4 ปีที่แล้ว

    You are so handsome So I got distracted easily

  • @aniceguy2577
    @aniceguy2577 4 ปีที่แล้ว

    Pls make a video doing the same thing but using react instead ✌🏻

  • @suryapratapsingh5149
    @suryapratapsingh5149 4 ปีที่แล้ว

    Please compile javascript interview questions for 10 years work experience developers

  • @CuongNguyen-nu3pn
    @CuongNguyen-nu3pn 4 ปีที่แล้ว

    I have seen this video: th-cam.com/video/Zi2UwhpooF8/w-d-xo.html of you. I got trouble at 29:46 in that video. I fill all the fields of book but i'm still get the error message and can not add book into db. Can u find out the bugs?