How To Build An Advanced Light/Dark Theme Toggle

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ • 98

  • @3FatesLive
    @3FatesLive 4 роки тому +43

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

  • @AnilKumar-f4u7l
    @AnilKumar-f4u7l Рік тому +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

  • @ScileSc
    @ScileSc 4 роки тому +25

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

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

  • @aimaneqbal
    @aimaneqbal 4 роки тому

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

  • @Almarexwebdev
    @Almarexwebdev 3 роки тому

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

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

  • @Berkeli
    @Berkeli 4 роки тому

    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

  • @wassimbelhadjrhouma7979
    @wassimbelhadjrhouma7979 4 роки тому +3

    I like the video before watching it 😍😍

  • @smokvin
    @smokvin 4 роки тому

    Thank you!
    You deserve more likes!

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

  • @leobailly1249
    @leobailly1249 3 роки тому

    Thanks ! Learned a lot ♥️

  • @gillbates9668
    @gillbates9668 2 роки тому

    thanks for this tutorial! very informative

  • @ГеоргиЧавдаров-в7з

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

  • @smcalpha
    @smcalpha 4 роки тому

    Nicely explained!

  • @raoulkhaleb7258
    @raoulkhaleb7258 4 роки тому +2

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

  • @mounir101
    @mounir101 4 роки тому +1

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

  • @usama57926
    @usama57926 4 роки тому +1

    amazing tutorial

  • @Star-zf8su
    @Star-zf8su 4 роки тому

    Thanks it helped me learn new properties 😍😍

  • @theretroman3862
    @theretroman3862 3 роки тому

    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!

  • @samaritan5744
    @samaritan5744 4 роки тому

    Nice work!

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

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

  • @azatecas
    @azatecas 4 роки тому

    Great tutorial

  • @hasanali6798
    @hasanali6798 4 роки тому

    hey man i love your work im doing this rn.

  • @usama57926
    @usama57926 4 роки тому +1

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

  • @samsalem6927
    @samsalem6927 3 роки тому

    amazing, thank you

  • @ssukhvant
    @ssukhvant 3 роки тому

    Amazing video

  • @leinyuymarie5570
    @leinyuymarie5570 13 днів тому

    I wish to ask why we couldnt put the sun and moon above the button and the title. Would that not save us complexity in the code and avoid the usage of position etc.

  • @tonyzhao7915
    @tonyzhao7915 4 роки тому +1

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

  • @Maldito011316
    @Maldito011316 3 роки тому

    How do you load it automatically then?

  • @travelingvibes7796
    @travelingvibes7796 4 роки тому

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

  • @rahuljoshi8331
    @rahuljoshi8331 3 роки тому

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

  • @xiaolong9446
    @xiaolong9446 4 роки тому

    Amazing lecture.

  • @vikasvk_
    @vikasvk_ 4 роки тому

    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

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 4 роки тому

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

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

  • @fabiof.deaquino4731
    @fabiof.deaquino4731 4 роки тому

    Thanks! :)

  • @rahulxdd
    @rahulxdd 4 роки тому

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

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

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

  • @wallijacanero1532
    @wallijacanero1532 4 роки тому

    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 4 роки тому +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!!!

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

  • @leonardorocca712
    @leonardorocca712 3 роки тому

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

    • @taksumaq
      @taksumaq 2 роки тому

      I use LocalStorage

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

  • @RusZakirov
    @RusZakirov 5 місяців тому

    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

  • @SauravKumar-pq8bo
    @SauravKumar-pq8bo 4 роки тому +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??

  • @davidjustice2323
    @davidjustice2323 4 роки тому

    I love you!

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

  • @brandonbh04
    @brandonbh04 Рік тому

    How about with React?

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

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

  • @rudestewing
    @rudestewing 4 роки тому

    thank's

  • @alimansimov1929
    @alimansimov1929 Місяць тому

    I think this is not a practical theme changer because you did overflow hidden on the body so the site can't be scrolled down if there are more contents and separate theme changer button do not look very well instead of the sun and the moon should behave as button but animation of svg and transition of colors was good.

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

  • @ItzSlacks
    @ItzSlacks 11 місяців тому

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

  • @PEACHWEALTHWALKER
    @PEACHWEALTHWALKER 4 роки тому

    Thumb Up

  • @superJerrySong
    @superJerrySong 4 роки тому

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

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

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

  • @sm1ley732
    @sm1ley732 4 роки тому +1

    i promise it is there xddd :D

  • @mikethegamedev
    @mikethegamedev 4 роки тому

    Can i code like this on Mobile?

  • @ImTheDot
    @ImTheDot 2 роки тому

    🌓

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

  • @user-zp1dv4yh5e
    @user-zp1dv4yh5e 4 роки тому

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

  • @daidandy
    @daidandy 4 роки тому

    nice boy

  • @CuongNguyen-nu3pn
    @CuongNguyen-nu3pn 4 роки тому

    I have seen this video: ua-cam.com/video/Zi2UwhpooF8/v-deo.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?

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