Build An Easy Light/Dark Mode Toggle With CSS & JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 เม.ย. 2023
  • 🚨🚨🚨 COURSES - slayingthedragon.io 🚨🚨🚨
    Join the discord - / discord
    Codepen for this - codepen.io/ramzibach-the-styl...
    To add dark mode to our website, we first need some elements in our HTML.
    All I have is button with the class of theme-toggle and an SVG icon inside it.
    Under the button, I also have an h1 that displays dark/light mode and under the h1, I have a paragraph that displays filler text.
    In my CSS, I don’t have much, I just have what’s needed for the layout to be in the middle of the page....
    Cursor icon from icons8.com/icon/14102/cursor
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Just to let everyone know, at 13:49 I define an arrow function but I forget to assign it in a variable. Code still works though but, you should probably add the const before handleToggleTheme. I'm a silly goose.

  • @shreyanshrathore6782
    @shreyanshrathore6782 11 หลายเดือนก่อน +13

    Loved the way, how you explained short circuiting....

  • @Palisis
    @Palisis 8 หลายเดือนก่อน +7

    Those extra 3 mins at the end are golden

  • @SaladHood
    @SaladHood ปีที่แล้ว +11

    I hope you produce more content mate. Your videos are so short and concise and I learn a lot from them. Very easy to understand and follow along.

  • @kudrah
    @kudrah 4 หลายเดือนก่อน +1

    Best Teacher. Please make more JavaScript Videos as well. You're enhancing my programmer thinking process.

  • @Zynix-
    @Zynix- ปีที่แล้ว +33

    You are so good at explaining things, your tutorials are so underrated 🔥
    your tutorials deserve attention..

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

      I appreciate that!

    • @DannyH77
      @DannyH77 9 หลายเดือนก่อน +1

      @@slayingthedragon when will JavaScript course be ready? i love the way you teach!!

    • @slayingthedragon
      @slayingthedragon  9 หลายเดือนก่อน

      @@DannyH77 Thank you, I just released the CSS course and courses take time to complete, so we're many months away from the JS course unfortunately, I'm doing my best though and I appreciate the interest 🙂

    • @DannyH77
      @DannyH77 9 หลายเดือนก่อน +1

      @@slayingthedragon OK ,Thank you

    • @DannyH77
      @DannyH77 9 หลายเดือนก่อน +1

      @@slayingthedragon I'm still struggling with grid, so I'll just keep practicing with that, and css animation until you put out JavaScript course

  • @methodboss6719
    @methodboss6719 ปีที่แล้ว +9

    Who wants a full course from this guy
    The way he teaches it's so understandable
    And excuse me for my English because I am not good at my English

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

      Your English is good, don't worry.

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

    You are AMAZING at explaining things! Showing examples, how one element is connected to another and giving most practical information as simply as it need to be.

  • @molostv2786
    @molostv2786 ปีที่แล้ว +18

    Young (14y/o) developer and i have to say, your videos are one of the most helpful ways i get new information on coding! much love from Kosovo

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

      That's so awesomeee! I hope you keep at it - I'm sure you'll go far !

    • @AkibAhmadGaming
      @AkibAhmadGaming 2 หลายเดือนก่อน

      @molostv2786 same here

  • @Vaannnard
    @Vaannnard 11 หลายเดือนก่อน +2

    Amazing videos! I've binge watched through your channel today and I'm happy I found it. It explains css units, flexbox, grids, positioning and very useful general knowledge really well!

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

    Excellent job. I really loved how you explained short circuiting. It’s such a powerful concept of JavaScript and when leveraged here, it makes a worlds difference.

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

    Your videos are the best on youtube about basic frontend. I need to understand the concept of :before and :after with the content:"" seems like a challenging video.

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

    Awesome and easy to understand video! Thank you very much. Cant wait to implement this to my own website. Keep up the great work. Greetings from switzerland

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

    I had never felt so comfortable learning with TH-cam videos until I came across your channel, I hope you can upload more content like this, because you really make very good content, I hope you can make a video about sidenav and how to align it correctly with Main in the center and the articles on the right side. Greetings from Mexico 🇲🇽

  • @jeremiah869
    @jeremiah869 10 หลายเดือนก่อน +1

    Literally the best web-dev content in the game, what an amazing channel

  • @bonezonechannel
    @bonezonechannel 8 หลายเดือนก่อน +1

    awesome! easy to follow, and allowed me to easily customize more to my wants. will be trying this method with another theme idea other than colors.

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

    Really good video! Very explicit and informative!

  • @KeyStroke_IT
    @KeyStroke_IT 10 หลายเดือนก่อน +1

    Love your work bro. Well paced and detailed videos. I'm watching from Nigeria. ✌🏾

  • @kyrilevangelista4056
    @kyrilevangelista4056 8 หลายเดือนก่อน +1

    Very informative and helpful, thank you so much! Subscribed as well

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

    Good content as always, also liked the playfullness on this one!

  • @Garvitjain-ru4ci
    @Garvitjain-ru4ci ปีที่แล้ว +1

    I am totally counting on you.
    Also expecting more content like this.

  • @mujtabakhan4521
    @mujtabakhan4521 ปีที่แล้ว +6

    you are my favouritteeeeeeeeeeeeeeeeeeeeee

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

    Yes... really great explanation...❤ We need entire real time project ( js or react) with same level of explanation

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

    Thank you so much, your video are amazing! Hugs from Italy 😊

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

      You wouldn't happen to know any DeMarco's there in Italy, would you?

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

    Bro I had issues understanding the guard operators coz I just started javascript. But I understand almost everything I see here. Well explained💯

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

    You are amazing ❤ love the way you explaine 😊

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

    Love ur content bro

  • @bowbowbow22
    @bowbowbow22 2 หลายเดือนก่อน +1

    You're an exquisite instructor.

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

    u are too good broo keep going

  • @andei9743
    @andei9743 11 หลายเดือนก่อน +2

    Beautiful explanation

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

    I'm here again. Your explanation is top notch

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

    Post more tutorials about JS.
    You are teaching better than Ask Lixi (and she is better than others!)

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

    good job man 🎉🎉

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

    You are doing very great. Please more vedios like thesee❤

  • @joelrhine
    @joelrhine 3 หลายเดือนก่อน +1

    The "floating there in nothingness" made me laugh more than it should have.

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

    Amazing!

  • @abbdd-zg7zy
    @abbdd-zg7zy ปีที่แล้ว +2

    thanks from syria and wish you Continue 🌹❤️

  • @user-vi5ub2wc6w
    @user-vi5ub2wc6w 5 หลายเดือนก่อน +2

    bro ure the best

  • @johndoe8091
    @johndoe8091 2 หลายเดือนก่อน

    Amazing videos dude, do you have a video on how to decouple scroll transitions from theme switching?

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

    Hey man, I have watched all of your videos and I have to say nobody has ever taught me that much about coding. Maybe in the future you can make a video about drop-down menus and how to make them. I'm sure this will be of great use. Thanks!

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

    nice video, I love ur teaching style please can u make a complete css lesson

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

    Amazing Video! Very clear and works great! 💯
    Just wondering if you knew how to make it remember your icons for dark/light modes on refresh? For example I have a moon for dark mode and a sun for light. Thanks in advance 😄

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

    can you talk about images and background properties and when to use them.ty and gj your content is very good and not too long

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

    Where are you ? Please come back ) We need more more new tricks, 3d and moreover which contain js projects

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

    Your are very helpful for me friend lovee from Pakistan ❤️❤️❤️

  • @mohamedibrahemsaad573
    @mohamedibrahemsaad573 10 หลายเดือนก่อน +1

    please come back We miss your channel

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

    You deserve millons of subs

  • @ronaldawudi-ackerman905
    @ronaldawudi-ackerman905 9 หลายเดือนก่อน +1

    Thanks

  • @reromsp
    @reromsp 10 หลายเดือนก่อน +1

    Expecting more js videos

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

    Your flex, grid and other css videos are too great.... please also make some videos on JavaScript ...i am really finding it hard....

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

      I will, I'm just finishing up my CSS course and I'll come back with weekly content on TH-cam !

  • @royalgreenchannel574
    @royalgreenchannel574 11 หลายเดือนก่อน +2

    please upload the videos on regular basis. at least weekly once . your videos are something special.
    make a videos on full stack development.

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

    To implement darkmode without JS,
    @media (prefers-color-scheme: dark) in CSS. do the work?

  • @alimansimov1929
    @alimansimov1929 3 หลายเดือนก่อน +1

    Truly excellent, when will your JS course come? I saw it on your website.

    • @slayingthedragon
      @slayingthedragon  3 หลายเดือนก่อน

      Some time during the summer

    • @alimansimov1929
      @alimansimov1929 3 หลายเดือนก่อน +1

      @@slayingthedragon the method you taught in this video was excellent I have never ever seen something like. I hope the method will be same.

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

    please am new to react and am having issues. Can you do a video on react? Touching on basic and one videos to create a single page website.

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

    Make a complete javascrit course plzz❤

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

    Can u pls created a video on javascript

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

    Hey man, are you still alive? I just discovered your channel, and you rock. Give us more tutorials, for sure with the correct affiliate programs you can make some good money, and it will be useful for us. Keep rocking, cheers|

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

    💯💯

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

    Create a full course on CSS and JavaScript

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

      I'm working on a CSS course right now! And after I'll release a free JS course on TH-cam as a playlist :p

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

    Next time do a calculator with js pls !!

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

    you are really professional, could I ask how many year do I need to become like you, I am still beginner?

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

      Heyy, everyones journey is going to be different, you just need to do your best and not give up ❤

  • @JulianStark
    @JulianStark 9 หลายเดือนก่อน +1

    Thanks for the great video! One question but I might be wrong: I think you put the js to the footer or end of body. Let’s imagine this is a big site with lots of content in the body. So if I load a new page and I’m already in dark mode I guess the colors will only switch to dark after the page has loaded and the js has been started. There will be some kind of flash from light to dark. Right? Would it be better, to put the code to the head?

    • @slayingthedragon
      @slayingthedragon  9 หลายเดือนก่อน +1

      Hey, I found this stackoverflow with a similar question to yours, the answer is pretty good! stackoverflow.com/questions/71799083/white-flash-on-dark-mode-on-refreshing-page

    • @JulianStark
      @JulianStark 9 หลายเดือนก่อน

      @@slayingthedragon thank you! so I guess the JS should be in the head with no defer in it

  • @tauromusic96
    @tauromusic96 9 หลายเดือนก่อน

    Hey good video! have a question, when i refresh the page still in dark mode it didn't change in sun but remain moon so i have to double click on it to return in light mode, how can i fix that? Thanks

    • @tauromusic96
      @tauromusic96 9 หลายเดือนก่อน

      I used font awesome icon so they change on click

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

    Bro please make video on Java script full

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

    Hey buddy do you use these concepts in production apps as well?? Or do you use any UI libraries??

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

      I use React and NextJS for anything production. However if I were tasked to do this in vanilla JS for production, I would do it exactly like I did it on the video.

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

      @@slayingthedragon Seeing from your portfolio video I'm guessing you use tailwind with Next JS🤔, I use the same.
      Can you advise me on usage of libraries like chakra in NextJS apps or should I stick with css/tailwind.

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

      @@srshah I can't speak for Chakra I've never used it. For styling I either use TailwindCSS or CSS Modules alongside NextJS.
      TailwindCSS is the only styling library I used, otherwise I really like normal CSS

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

    Ternary operators can be used to shorten the code.

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

      Did you watch the entire video ?

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

      Yeah 👍 I know what you mean

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

      Much love ❤️

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

      @@slayingthedragon Hey I'm working on a personal project. Need to use REM as breakpoints. But it has issues so JS implementation will work I guess.

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

    What is this theme in vs code? Thanks

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

    Hello I have a question regarding the making the code more readable, where do I place the function?
    Place it under handlers comment or place it at the very top of the code or at the very bottom of the code?
    function abc() {
    alert("Hi");
    }

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

      Placing it under the handler comment makes it the most readable. You don't want your functions at the top, it makes more sense to have your selectors at the top.
      I didn't invent this pattern, JavaScript frameworks like React use a very similar structure and the way I structured it in the video is most recognizable for other developers.

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

      @@slayingthedragon Thank you! Love your videos. I hope you consider to upload framework tutorial in the future.

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

    Bro upload new video related to css

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

    Dddamn, how you good at css and brawl 😔

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

      Haha this one is actually JavaScript but thank you ☺️❤️

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

    You need to start a course or something

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

    Pls java script tutorial series 🥲🤌

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

    " We can do better"

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

    Thanks