How To Build An Advanced Light/Dark Theme Toggle

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • 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/Web...
    CodePen Code: codepen.io/Web...
    Emmet Tutorial: • Learn Emmet In 15 Minu...
    Material Design Icons: materialdesign...
    🧠 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.webdevsim...
    My Courses: courses.webdev...
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/Web...
    CodePen: codepen.io/Web...
    #ThemeToggle #WDS #LightDarkMode

Комментарии • 96

  • @3FatesLive
    @3FatesLive 4 года назад +43

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

  • @ScileSc
    @ScileSc 4 года назад +25

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

  • @user-yw4wc2fy3u
    @user-yw4wc2fy3u Год назад +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

  • @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!

  • @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

  • @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! 👍🏼

  • @aimaneqbal
    @aimaneqbal 3 года назад

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

  • @DavetheTrainer
    @DavetheTrainer 4 года назад +2

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

  • @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!

  • @arnav_0397
    @arnav_0397 3 года назад

    tons of appreciation is even not enough to appreciate you!

  • @raoulkhaleb7258
    @raoulkhaleb7258 3 года назад +2

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

  • @Berkeli
    @Berkeli 3 года назад

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

  • @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

  • @gillbates9668
    @gillbates9668 2 года назад

    thanks for this tutorial! very informative

  • @user-mg3ok3tv1e
    @user-mg3ok3tv1e 4 года назад

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

  • @wassimbelhadjrhouma7979
    @wassimbelhadjrhouma7979 4 года назад +3

    I like the video before watching it 😍😍

  • @mounir101
    @mounir101 4 года назад +1

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

  • @leobailly1249
    @leobailly1249 2 года назад

    Thanks ! Learned a lot ♥️

  • @usama57926
    @usama57926 4 года назад +1

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

  • @Star-zf8su
    @Star-zf8su 4 года назад

    Thanks it helped me learn new properties 😍😍

  • @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!

  • @smcalpha
    @smcalpha 4 года назад

    Nicely explained!

  • @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.

  • @tonyzhao7915
    @tonyzhao7915 4 года назад +1

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

  • @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!

  • @smokvin
    @smokvin 4 года назад

    Thank you!
    You deserve more likes!

  • @samsalem6927
    @samsalem6927 2 года назад

    amazing, thank you

  • @azatecas
    @azatecas 4 года назад

    Great tutorial

  • @samaritan5744
    @samaritan5744 4 года назад

    Nice work!

  • @user-uo7bq9km4t
    @user-uo7bq9km4t Месяц назад

    Nice project and good walk through but, I wish that more javascript was used in this tutorial. I didn't like the fact that allot of what could be done in js file, was done in css file instead

  • @hasanali6798
    @hasanali6798 4 года назад

    hey man i love your work im doing this rn.

  • @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?

  • @Maldito011316
    @Maldito011316 2 года назад

    How do you load it automatically then?

  • @rahuljoshi8331
    @rahuljoshi8331 3 года назад

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

  • @rudestewing
    @rudestewing 3 года назад

    thank's

  • @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?

  • @ssukhvant
    @ssukhvant 3 года назад

    Amazing video

  • @fabiof.deaquino4731
    @fabiof.deaquino4731 4 года назад

    Thanks! :)

  • @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 года назад

    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

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 4 года назад

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

  • @travelingvibes7796
    @travelingvibes7796 4 года назад

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

  • @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

  • @brandonbh04
    @brandonbh04 Год назад

    How about with React?

  • @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.

  • @xiaolong9446
    @xiaolong9446 3 года назад

    Amazing lecture.

  • @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.

  • @ItzSlacks
    @ItzSlacks 7 месяцев назад

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

  • @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??

  • @ipeach7278
    @ipeach7278 4 года назад

    Thumb Up

  • @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!!!

  • @davidjustice2323
    @davidjustice2323 4 года назад

    I love you!

  • @sm1ley732
    @sm1ley732 4 года назад +1

    i promise it is there xddd :D

  • @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.

  • @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.

  • @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?

  • @leonardorocca712
    @leonardorocca712 3 года назад

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

  • @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.

  • @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).

  • @daidandy
    @daidandy 4 года назад

    nice boy

  • @ImTheDot
    @ImTheDot Год назад

    🌓

  • @eduardmorarus
    @eduardmorarus 4 года назад

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

  • @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.

  • @mikethegamedev
    @mikethegamedev 3 года назад

    Can i code like this on Mobile?

  • @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

  • @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

  • @onemorestory1
    @onemorestory1 4 года назад

    You are so handsome So I got distracted easily

  • @suryapratapsingh5149
    @suryapratapsingh5149 4 года назад

    Please compile javascript interview questions for 10 years work experience developers

  • @CuongNguyen-nu3pn
    @CuongNguyen-nu3pn 4 года назад

    I have seen this video: ruclips.net/video/Zi2UwhpooF8/видео.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?

  • @aniceguy2577
    @aniceguy2577 4 года назад

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