Light/Dark Theme Toggle with CSS and JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2019
  • 👉 Daily Coding Challenges: iCodeThis.com/?ref=ytb-theme-...
    In this tutorial, we are creating a Dark/Light Theme Toggle effect using vanilla #CSS and #JavaScript. This is a perfect component to be used on a website that has a Dark theme mode.
    #100Days100Projects Challenge: www.florin-pop.com/blog/2019/...
    Source Code: codepen.io/FlorinPop17/pen/XW...
    #css #javascript
    ---
    Support my channel:
    💜 Become a Member of the Poppers Family and receive special perks: th-cam.com/users/florinpopjoin
    💜 Donate via StreamLabs: streamlabs.com/florinpop2/
    💜 Donate via PayPal: paypal.me/florinpop17
    💜 Become a patron: / florinpop17
    Thank you! 🙏
    ---
    👨‍👩‍👧‍👦 Join the Discord family: / discord
    ---
    Follow me on:
    📃 Website/Blog: florin-pop.com
    👉 Twitter: / florinpop1705
    👉 Linkedin: / florinpop17
    👉 Instagram: / florinpop17
    👉 Facebook: / florinpop17
    👉 Github: github.com/florinpop17
    👉 Dev.to: dev.to/florinpop17
    👉 Twitch: twitch.com/florinpop17
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Thanks very much! This is exactly what i needed! Keep up the good work!🔥

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

    This is by far the most cool and simplified video about Dark Mode on web design I've ever seen. Thanks!

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

    Your dimensions are always good! I like the way you use them

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

    You are just amazing Florin Pop. Nice Tutorial.

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

    Thanks for including source code! More people should do so in their descriptions.
    I'm very grateful.

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

    Thank you so much Florin, you're my favourite TH-camr!

  • @chiemelieakah5831
    @chiemelieakah5831 4 ปีที่แล้ว +26

    I have been searching for a simple explanation on how to do this. thanks a lot

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

      My pleasure

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

    You have explained every line of code and I can make a theme switcher anytime I want without watching any tutorial. Thanks a lot.

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

    By hiding the actual input you lose the ability to navigate the switch using the keyboard (tab + space). A solution to this would be to place the input inside the label (absolute), make it transparent and make it the same shape as the label. That way it works both with mouse as well as keyboard events. Also it would be good to set some hover/focus styles for accessibility.

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

    Very nice. I learnt a lot. Cheers mate!

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

    Nice video! I have always wanted to learn to make a dark mode toggler. Thanks for making this a short and concise tutorial!

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

      My pleasure! Thanks for watching ☺️

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

    Loved this tutorial! It was an absolutely amazing beginner-friendly explanation! Thanks a lot, @Florin Pop! ❤

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

    Thank you very much, Florin. This was very helpful.

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

    Excellent vid, clear and concise. Thank you!

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

    Thank you, Florin! I really appreciated this tutorial! ☺

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

      Glad you found it useful 😃

  • @baba-ogulkeyfi9083
    @baba-ogulkeyfi9083 2 ปีที่แล้ว

    thank you florin poppp!

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

    It's beautiful and so smooth that you explain

  • @cap.blue-97sama99
    @cap.blue-97sama99 3 ปีที่แล้ว +1

    Wonderful Explanation!!:)))

  • @AJAYSINGH-jo7hg
    @AJAYSINGH-jo7hg ปีที่แล้ว

    very well explained cleared all concepts. THANKS..!!

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

    I love it!

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

    Thanks Bro..loved the tutorial

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

    Thanks Florin very cool

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

    This was great, thank you!

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

      My pleasure to help!

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

    Thank u so much I use your toggle component

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

    nice video!!! thanks man

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

    Thank you

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

    thank you bro it is very useful video
    i wait new video from you

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

    Your tutorials are really excellent, you deserve many more subscribers !

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

      Thank you Maxime!

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

      @@FlorinPop Hi @Florin pop!
      I'm using the vscode. I donno how to add that extension or import that font awesome thing in that vscode. Could u please help me?

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

    You should make a video tutorial on each one of your 100 projects in 100 days

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

    Awesome !

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

    Thanks lot sir✨

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

    this actually helped me

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

      Glad it did!

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

    Hi @Florin pop!
    I'm using the vscode. I donno how to add that extension or import that font awesome thing in that vscode. Could u please help me?

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

    Thanks, sir, its awsome.

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

    thanks!

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

    You're amazing

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

      You’re amazing! 😃

  • @MIJones-hm5gz
    @MIJones-hm5gz 3 ปีที่แล้ว

    How can I both move the ball and change the background color when I click the switch?

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

    Great video, I love the button but for some reason my checkbox is not working... does this work in Blogger?

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

    Awesome

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

    Thanks alot

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

    hai, how about each of both toggle dark or light functional and keeps staying each of button when we refresh the page.

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

    Hey Florin! when I tired styling the ball div in CSS , its not showing up for me. What am I doing wrong?

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

    Is there a way to use this to enmass change the colour of all text without going: body.dark p { colour ... then same for h1 and same for everything??

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

    thanks

  • @AhmedRaza-rm9ld
    @AhmedRaza-rm9ld 4 ปีที่แล้ว +4

    Liked before watching ❤️...

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

    How I change the font color when change theme?

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

    love it...Keep going dude!

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

    Very nice

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

    Project very explained very well👍🏽.
    I understood how you changed the paragraph colour while toggling. I would like to know if there is a more efficient way to do this when many elements are present. Do we have to do 'body.dark element{} ' for each individual element if we want the colour to be changed to a different colour while toggling?

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

    thanks a lot ❤️❤️

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

      My pleasure 👍🏻

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

    Thank you ❤️

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

      My pleasure 🙏

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

    Anyone have an idea why mine would work on codepen but not in chrome?

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

    so if u have 20 element u want to change on dark mode u will have body.dark "element" 20 times too? How to override a root variable on dark mode

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

    Why aren't you implementing the clicking event in js?

  • @vishal-jv2rw
    @vishal-jv2rw 3 ปีที่แล้ว

    Hey where we past it in blogger.

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

    How do you load it automatically then?

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

    Thanks

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

    Why do moon and sunlight icon don't show

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

    Great❣️

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

      Thank you 🙏

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

    Thank you for very nice tutorial , Florin!!
    Have one question about CSS style, what is the difference between "body.dark" and "body .dark" (with space) ?

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

      With the space it goes to a inner element that has a class of .dark. But we want to target the body which has the class of .dark so that’s why we have: body.dark

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

      Florin Pop thanks !!

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

    I'm trying to build this feature into HTML pages I'm creating on VSCode, this IDE doesn't have those three boxes marked HTML CSS JS, can somebody help me few moments please, for aspiring junior software developer? I've got my HTML page editor open in VSC, obviously it's not hard to apply all these CSS attributes between tags in of my code, but where does the JavaScript go into? Into tags perhaps? And then place script tags below tags in the body?

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

      I am sorry that nobody gives a fuk to help you here...
      You need to create a new java script file for example theme_checkbox.js then enter all the code there:
      const chk = document.getElementById('chk');
      chk.addEventListener('change', () => {
      document.body.classList.toggle('dark');
      });
      Once you complete that step you go to your HTML file (the one that you are trying to add that feature to) and then just before the tag you add this line (of course you need to replace /static/js/theme_checkbox.js with your path to the javascript file):
      I hope that helps and all the best with your career!

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

    Source code with explanation! this is a gem thank you

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

    I love you so much

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

    Another Great video Florin.
    Keep it up.
    Little suggestion: Please improve the audio quality if possible 😊

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

      @@FlorinPop That's great buddy. Looking forward 😉

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

    Hey man this is cool stuff!!!! I really appreciate you and one suggestion kindly increase font size bcoz its too small

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

      Did it in newer videos ☺️

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

    What IDE do you use?

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

    Hello sir,
    How to apply it to id?
    #idName.dark somehow does not work.

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

    Can we merging the html, css, and javascript into 1 worksheet?
    If yes, then the structure looks like this? (without '.' in the style sett), ex:

    h1 { color: #999; font-family: sans-serif}


    bla bla bla

    or this one (with '.' in the style sett) ?

    .h1 { color: #999; font-family: sans-serif}


    bla bla bla

    About the javascript, where to put?

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

    Cool

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

    I have seen your challange 100 project per 100 days, and I accepted demo version for 30 projects per 30 days for a start, thanks for idea.
    By the way also I have seen your first project with random generator meals, can you create video tutorial how you create this with comment?:)

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

    Can you make it work when you navigate to a different page on the same website?

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

      Yes. Store it in localstorage

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

      I have done that, but still doesn't work

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

      Join the discord and let’s see

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

      Can you please help me with that? I'm not very good at js

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

      As I said, join the discord as it’s easier to help you

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

    How could I change the background for classes? I did Const x = document.getElementsByClassName(‘ links’); x.classList.toggle(‘dark’); It didn’t work.

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

      getElementsByClassName will get you a NodeList so you basically have multiple Nodes. This is why it doesn't work.
      You have to loop over them (the Node items) and toggle the class list.

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

      Florin Pop Thanks for the reply

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

      @@FlorinPop can u please share the code or make a tutorial on toggling classes?

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

    Please how can I make this to be static if I refresh it will just diaappear

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

      by local storage

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

    what kind of sorcery is this? ie when you typing .ball it becomes .WHY?HOW?I NEED THAT TOO

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

      It is called emmet. It's an extension

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

      @@FlorinPop thanks, chief! I see it all the time in videos and nobody bats an eye nor hints to why this is happening. Googled it, installed it, using it. Thanks to you, my man

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

    fas fa-moon and sun not working in my pc but i had linked font awesome cdn

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

      Ever find a solution to this?

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

    I wrote same code of all 3 files but the pictures ( of moon and sun) near ball are not on my screen. What can be the reason?

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

      You might be missing the fontawesome library

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

      @@FlorinPop It works. Thanks !

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

    What's that font thing you had to download at 2:53?

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

    my is not working maannnn

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

    💓

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

    good traning

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

    how do i make this affect letters, rn, it only affects background colors?

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

      You can change the color property

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

      @@FlorinPop how would i do that? what would the code look like if I did that? btw i'm so suprised u actually replied!

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

      What have you tried so far?

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

      @@FlorinPop nothing yet, i was hoping for some suggestions for me to do or code snippets so i could put them in the code?

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

      body
      {
      color: black;
      background-color:white;
      }
      body.dark
      {
      background-color: black;
      color: white;
      }
      const checkbox = document.getElementById('checkbox');
      checkbox.addEventListener('change', () =>{
      document.body.classList.toggle('dark');
      })
      anyone know why this doesn't work for the text? it only changes bg color

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

    i saw your comment on dev ed and came here

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

      @@FlorinPop OMG that was fast did you make a bot to replay????

  • @user-florin
    @user-florin 4 ปีที่แล้ว +3

    🌝👍

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

    i dont have this sun and moon on the button, help

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

      Add this to your HTML and you should be OK.

    • @prod.bvllxt4475
      @prod.bvllxt4475 3 ปีที่แล้ว

      @@janchalupsky3211 Thanks a lot man, I was struggling to find something about it hehehe

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

    It works great though i don't get white it won"t stay in dark mode with my pagination

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

    name of the code editor pls?

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

      codepen.com

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

    100 projects in 100 days

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

    Getting this: "ERROR: parsing error: The keyword 'const' is reserved". Any advice?

    • @hope-ag
      @hope-ag 3 ปีที่แล้ว

      Are you trying to assign const to a variable, function, etc........have you named anything const in your code?

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

      I copied the code line to line into my project. So no, i guess i haven't named anything "const". :D JS is a new thing for me and i've tried everything to make this work. Weird thing is, it works on online code editors, but not on dreamweaver or visual studio code.

    • @hope-ag
      @hope-ag 3 ปีที่แล้ว

      @@boostas9842 which line is the error on?......it's usually printed alongside the error message

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

      @@hope-ag It's on the first line of the js code

    • @hope-ag
      @hope-ag 3 ปีที่แล้ว

      @@boostas9842 const chk = document..............You sure the "chk" is in the line?

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

    Why every developer has diffent types of coding method? .

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

      We are different people.

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

      As a newbie its hard to follow. But slowly i understand. Do you recomend weschool? Just for the command though.

  • @Gabriela-ld8ri
    @Gabriela-ld8ri 3 ปีที่แล้ว +1

    Mine is not working, I get the icons (moon & sun), but It's not getting dark, u know? No transition... does anyone knows why?

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

      Hi, did you find what was wrong? I have the same problem

    • @Gabriela-ld8ri
      @Gabriela-ld8ri 3 ปีที่แล้ว

      @@Leilektsoglou I've watched another tutorial and fixed it

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

      @@Gabriela-ld8ri Please, send the link if it's easy for you

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

      @@Leilektsoglou The code needs to be placed within but AFTER the checkbox code. This is because the JS is dependent upon that checkbox; if the script is placed above it the script doesn't know what checkbox to refer to. (CC: David T)

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

    Why can't you teach to build a UI design from uplabs. We can learn how to convert a design to UI. Please do that for front end beginners

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

      I did that in my live streams

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

      I checked that
      Did you mean that portfolio design.Yes we need more design like this.For example web apps ui,web apps js interaction like that
      Kindly request you to do that type of video

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

    Thank you

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

    Thank you