Light/Dark Theme Toggle with CSS and JavaScript

Поделиться
HTML-код
  • Опубликовано: 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: ruclips.net/user/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

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

  • @chiemelieakah5831
    @chiemelieakah5831 4 года назад +26

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

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

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

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

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

  • @visivoo3845
    @visivoo3845 3 года назад +15

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

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

    You are just amazing Florin Pop. Nice Tutorial.

  • @00el04
    @00el04 3 года назад +2

    Thank you so much Florin, you're my favourite RUclipsr!

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

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

  • @andreimuntean1
    @andreimuntean1 3 года назад +1

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

  • @marisa2854
    @marisa2854 Год назад +1

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

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

      Glad you found it useful 😃

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

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

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

    Excellent vid, clear and concise. Thank you!

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

    Very nice. I learnt a lot. Cheers mate!

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

    It's beautiful and so smooth that you explain

  • @AJAYSINGH-jo7hg
    @AJAYSINGH-jo7hg Год назад

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

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

  • @baba-ogulkeyfi9083
    @baba-ogulkeyfi9083 2 года назад

    thank you florin poppp!

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

  • @saffron6661
    @saffron6661 4 года назад +5

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

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

    Thanks Bro..loved the tutorial

  • @cap.blue-97sama99
    @cap.blue-97sama99 3 года назад +1

    Wonderful Explanation!!:)))

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

    This was great, thank you!

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

      My pleasure to help!

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

    Thank u so much I use your toggle component

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

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

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

    Thanks Florin very cool

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

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

  • @prodbybarn
    @prodbybarn 8 месяцев назад

    Thank you

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

    I love it!

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

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

    this actually helped me

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

    nice video!!! thanks man

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

    Thanks lot sir✨

  • @MIJones-hm5gz
    @MIJones-hm5gz 3 года назад

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

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

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

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

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

    Awesome !

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

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

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

    Thanks, sir, its awsome.

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

    love it...Keep going dude!

  • @anvoids
    @anvoids 2 года назад +2

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

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

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

  • @AhmedRaza-rm9ld
    @AhmedRaza-rm9ld 4 года назад +4

    Liked before watching ❤️...

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

    You're amazing

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

      You’re amazing! 😃

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

    How I change the font color when change theme?

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

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

    thanks!

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

    Source code with explanation! this is a gem thank you

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

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

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

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

    Thanks alot

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

      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!

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

    Why do moon and sunlight icon don't show

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

    What IDE do you use?

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

    thanks

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

    thanks a lot ❤️❤️

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

      My pleasure 👍🏻

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

    Awesome

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

    Thank you ❤️

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

    Very nice

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

    Great❣️

  • @JamesHyunwooLee
    @JamesHyunwooLee Год назад +1

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

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

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

    How do you load it automatically then?

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

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

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

    Thanks

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

    I love you so much

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

    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  3 года назад +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 3 года назад

      Florin Pop Thanks for the reply

    • @seino__
      @seino__ 3 года назад +1

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

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

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

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

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

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

    Cool

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

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

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

    my is not working maannnn

  • @user-toxin1377
    @user-toxin1377 Год назад

    good traning

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

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

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

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

  • @user-bp3pu7ph8y
    @user-bp3pu7ph8y 3 года назад

    name of the code editor pls?

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

      codepen.com

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

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

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

    100 projects in 100 days

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

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

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

    💓

  • @user-florin
    @user-florin 4 года назад +3

    🌝👍

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