Это видео недоступно.
Сожалеем об этом.

Full Dark Mode with only 1 CSS PROPERTY?!

Поделиться
HTML-код
  • Опубликовано: 9 сен 2020
  • Visit linode.com/desi... for a $20 credit on your new linode account.
    designcourse.com - Learn UI/UX from Scratch with my new service (coming soon)
    -- Today, we're going to see if you really can create a dark mode version of your site with only 1 line of css. This video was inspired by Ekaterina Vujasinović, who wrote this article on the subject: dev.to/ekateri... (Give her a follow!).
    Let's get started!
    - - - - - - - - - - - - - - - - - - - - - -
    Subscribe for NEW VIDEOS!
    My site: designcourse.com
    My personal FB account: logodesi...
    Coursetro FB: coursetro
    Coursetro's Twitter: / designcoursecom
    Join my Discord! / discord
    ^-Chat with me and others
    - - - - - - - - - - - - - - - - - - - - - -
    Who is Gary Simon? Well, I'm a full stack developer with 2+ decades experience and I teach people how to design and code. I've created around 100+ courses for big brands like LinkedIn, Lynda.com, Pluralsight and Envato Network.
    Now, I focus all of my time and energy on this channel and my website Coursetro.com.
    Come to my discord server or add me on social media and say Hi!

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

  • @DesignCourse
    @DesignCourse  3 года назад +158

    Do you dark mode every layout?

    • @LabhamJain
      @LabhamJain 3 года назад +12

      Yeah! I Love Making Themes Muhha!😘😘😘

    • @DesignCourse
      @DesignCourse  3 года назад +7

      @@LabhamJain It really is fun.

    • @LabhamJain
      @LabhamJain 3 года назад +7

      Wait I've Mind Bowling Idea For Figma... Open Your Prototype (design) Then Open Devtools With Menu Bar Of Browser Select HTML tag click element style paste this... boom 💥💥💥💥💥 😂😂😂😂

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

      No mucg

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

      I make it so it's unique and not too bright

  • @Itschotsch
    @Itschotsch 3 года назад +400

    The property is:
    .dark-mode {
    filter: invert(1) hue-rotate(180deg)
    }

  • @thmsmlr
    @thmsmlr 3 года назад +646

    1 line of CSS, 12 minute video 🤣

  • @DevProTips
    @DevProTips 3 года назад +40

    The real tip is to use:
    html, img, video, {
    filter: invert(1) hue-rotate(180deg)
    }
    That way everything is inverted, but images and embedded content don't get messed up.

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

      Thanks

    • @creedolala6918
      @creedolala6918 3 года назад +7

      This seems to only invert the unwanted stuff. What you can do is html { filter:invert(1) } then on a separate line
      img, video, { filter: invert(1)}.
      I thought the images and videos needed something like invert(0) to "uninvert" but it turns out they just need to be 'double inverted' to return to normal.

    • @ceptember.
      @ceptember. 2 года назад

      🌟

  • @stefanschlipfinger5916
    @stefanschlipfinger5916 3 года назад +148

    The new Edge Browser is Chromium based 😅

    • @maabed1022
      @maabed1022 3 года назад +12

      @Xero Garbage? It's pretty decent to me.

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

      @@MuhammadHosny0 Exactly! And to be completely honest , the channel's owner sounded a bit condescending when he mentioned edge's compatibility. Albeit, I think it came from a place of ignorance rather that dumb hatred.

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

      maabed sj calm down you guys, it’s just a meme

    • @maabed1022
      @maabed1022 3 года назад +6

      ​@Xero lol what gives? How's Google any different?

    • @michaelbitzer7295
      @michaelbitzer7295 3 года назад +3

      @Xero lol why do you even use RUclips if you are concerned about privacy

  • @minecrap5256
    @minecrap5256 3 года назад +32

    By the way, the new microsoft edge is based on chromium . This means that everything that works in chrome (including extensions) works in edge aswell.

    • @MrTHEO9911
      @MrTHEO9911 3 года назад +11

      Yeah just recently complete moved to edge, it just feels faster and smoother than chrome and now I can import passwords, settings and extensions. I was sold

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

      Thank you, just wanted to say the same, he should pin this comment lol

  • @davidfitcher2953
    @davidfitcher2953 3 года назад +16

    0:56 when the bell hits the throat

  • @Tortuex_
    @Tortuex_ 3 года назад +54

    Maybe a simple ".dark-mode::not(.inverted)" would work?
    It would only invert and change the hue of the elements that are not tagged with the "inverted" class (if I keep the same name than in your example).
    That would allow to *remove any JavaScript* (except for the enter switch in this case) and *keep it all CSS based* and *only within one single line* .

    • @z-aru
      @z-aru 3 года назад +2

      Neat Solution

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

      @@z-aru thanks ^^

    • @szegedigergely
      @szegedigergely 3 года назад +6

      "filter" is applied to the ".dark-mode" container itself, so whatever there is inside that, gets inverted, you cannot exclude elements like that. However, you can reverse the effect by re-applying it like ".dark-mode, .dark-mode .inverted { filter: invert(1) hue-rotate(180deg) }"

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

      @@szegedigergely good to know :)

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

      @@szegedigergely So like a double no is a yes.

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

    For images, you can also use the :not(img) selector, so that the filter does not apply for every image element!

  • @tcroft
    @tcroft 3 года назад +6

    This is actually really interesting, you could try just applying that class to all img tags instead of manually adding an inverted class. The hue rotate is a really clever way of bypassing dodgy inversions which is cool

  • @javiarenas
    @javiarenas 3 года назад +12

    So you’re telling me that in order to keep some things unchanged, the way you recommend is to change them, then applying a script to loop trough each element that has a given class, to then reapply the same change you did in the first place so that it comes back to original? That seems efficient

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

      Whats your solution

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

      This solution by @Tortuex in the comments seems like the best:
      Maybe a simple ".dark-mode::not(.inverted)" would work?
      It would only invert and change the hue of the elements that are not tagged with the "inverted" class (if I keep the same name than in your example).
      That would allow to remove any JavaScript (except for the enter switch in this case) and keep it all CSS based and only within one single line .

  • @ArtsandGadgetsStuff
    @ArtsandGadgetsStuff 3 года назад +8

    The thing I am waiting for a long time!! Thank you

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

    Perhaps you might add a "data-revert" (Or something like that) to personalize the degre of invertion for specific elements

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

    Anything can be done with one line of code. It’s just gonna take a lotta side scrolling...

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

    It's great to see this. I have been managing a dark / light mode and it can be a bit if a pain to manage. But it's a really great feature for users.

  • @Peter-A
    @Peter-A 3 года назад +21

    Edge is chromium based not IE based.
    Technically it's rebadged google chrome.

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

      Technically Edge is rebadged Chromium, such as Google Chrome is rebadged Chromium.

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

      almost all browsers currently are chromium based, it's just simple and open source enough to just work

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

    Actually the Edge Browser is based on Chromium. So showing the working example is a bit redundand.

  • @RanjanKumar-bu7ws
    @RanjanKumar-bu7ws 3 года назад +2

    The firefox bug can be solved by explicitly adding background-color : white to the root pseudo class

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

    Hey i just thought of two things u might want to know
    1. You probably already know, but, you can press the new file button and write css/style.css. This will quickly create the necessary folders as well as the file.
    2. I didn't personally test this, but I feel like it should work. Why even do a for each loop in javascript for reversing the css filter property, why not just in the css write
    .dark-mode .invert {
    // That invert css line
    }

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

    Don’t be surprised it works in Edge as it is a mere ms copy of Chrome. Safari would be a great place to check if it works, along with mobile browsers

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

    I love just how creative people can be. This is great!

  • @andresfuenzalida869
    @andresfuenzalida869 3 года назад +5

    I noticed that you can play with the hue-rotate value and it will change a little bit the colors. Nice video!

  • @artaizen1613
    @artaizen1613 3 года назад +7

    IE : "I'll ruin this trick.... oh also almost every css js anything you throw at me, unless.... I approve of it"

  • @birsingh5388
    @birsingh5388 3 года назад +9

    10:33 looks like you are watching lots of Ed's videos these days 😂

  • @Telladriel
    @Telladriel 3 года назад +13

    Lmao I could see the fear in his eyes when he wrote that one line that all viewers will click off the video cause they got what they came for. Gotta pump up that watch time tho

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

    JS noob here.
    Gary, I assume when you double invert, you are wasting CPU cycles. Is there a better way to do it?
    Or is this method just a quick and dirty hack?

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

    Edge is based on Chromium which means anything that works on Chrome works on Edge ... Great Video

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

    Loved the music towards the end, haha. Great content btw!

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

    You can also use :not(.inverted) psudo selector to ignore inverted class.

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

    I don't know if it's already fixed, but in Mozilla Firefox, the body background is fixed by manually adding a background to the body.

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

    I know this isnt what the video is about, but you should write `e = e ?? window.event` I'm not sure if `??=` is wildly supported yet, but we worked hard for the `??` operator.

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

    Why would you be surprised that it works in Edge? It's basically the same browser as Chrome now.

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

    Didn't know about that property. Thanks Badboy

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

    Can you make the video about your setup device and application you are use for make your youtube video ? I was so admire with each video your make. Its like so smooth and i cant find the bad thing in every 1 second in video.

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

    This video was so helpful for me . Dark mode is headache to implement with css and javascript.
    But this method can be very very useful and effective with some extra work 💪

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

    It works on MS Edge as the base of that browser is Chromium. Just an FYI for those who are asking

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

    Well, Microsoft Edge is actually a repackaged Chromium browser (the open-source version of Google Chrome) so everything that works in Chrome should technically work in Edge too.

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

    I've used this for a long time myself.
    filter: invert(100%) hue-rotate(180deg)

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

    Sin Palabras
    Grandioso Video, Thanks!

  • @alex-suciu
    @alex-suciu 3 года назад

    since you are on windows, you can use windows button and V, when paste. it will enable copy clipboard. 😎

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

    you could just invert the black and white, find and replace swap

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

    Crazy, great video thanks a bunch.

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

    After seeing this video, I made a small JavaScript to automate the idea :)
    you can find the source code on github: github.com/AspieSoft/toggle-darkmode-js
    Simply add the script (and jQuery), and everything runs automatically.
    It auto detects the brightness of each color, and detects "prefers-color-scheme" to set the right mode (including live updates)

  • @fredrikstrm-larsen7803
    @fredrikstrm-larsen7803 3 года назад +1

    What if you used brightness(10%) on the last "boxes" or the images where invert() doesn't look good?

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

    This method is very slow on lower-end computers. I tried it on a laptop with an Intel i3-6100U, 4GB RAM (running an Arch-based distro) and the smoothness of my bare bones website went from smooth to choppy. Maybe I'll do something else for it.

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

    Edge is chrome with windows label, so yes it will work with it

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

    I think that it's not working in Firefox because body in it may be actualy transparent instead of white.

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

      Maybe if you set body background to #fff it will work.

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

    Just at the right time. Thanks

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

    why not select the body with document.body instead of whatever you did

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

    hmm a bit finicky in converting solid yellows and greens on logos and backgrounds back to the original (using Chrome 85). needed to put more effort in excluding these images, svgs, and component with yellow and green background colors from the application of the filter effect. as said in the video, if you are not strict with brand colors, this will suffice. if your CSS framework supports dark mode, I think that's better.

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

    Last time I checked Edge had better support than firefox, and its based on the same engine as chrome.

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

    sir when i open dropdown menu and i used marquee text marquee text shown over dropdown how can i solve it

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

    It doesn't work on text shadows, font color, border colors , or gradients though.

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

    Firefox has default white background in HTML tag. Edge is based on Chrome, so...

  • @Misfit-nd3zk
    @Misfit-nd3zk 3 года назад

    Hey i need a help, i want to make checkbox which toggles dark mode, how can i use this property , i will be waiting for the response, Thank You

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

    I have previously used inverted for my own profile page... But using this methode turns out to be a bit heavier for the computer as it is calculating realtime. That's why I had to ditch this method for the favour of performance. Otherwise it is cool for quick demo.
    For me the problem turned out to be the scroll became sluggish

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

    that is really cool dude

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

    nice trick Gary, regards from Paraguay..

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

    Nice video.. learnt something cool feature.. ✌️

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

    How about a toggle switch button? Sun and Moon. Where I can find it?

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

    Awesome dude !!!! keep it up

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

    Hi I loved the content. But again how do we fix that issue of about fire fox not giving dark background

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

    You should not do the js loop to add a new class, you can use the css selector ".dark-mode .inverted {" instead

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

    and if i have a background img in the body tag haw can i invert that img to look normaly?

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

    very useful! Thank you

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

    I can see the use of this for very quick mockups, as you and the original blog post said. In the real world, though, how do you design 'dark mode' implementations? I've never done one, but I'd imagine CSS custom properties are the way forward, right?

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

    You are the linode!

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

    Great, thank you! Has anyone figured out how to make this work across all browsers please?

  • @TheFlexy95
    @TheFlexy95 3 года назад +12

    The new edge is based on chrome 😅 so it’s using webkit Now.
    Good vid anyway 👍🏼

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

      Chrome doesn’t use webkit

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

      @@ownadi You're right, it uses 'blink' now, in the past chrome used Webkit :P

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

    I'm a complete noob in css, so please don't hammer me if this is wrong! Could you do it as, for example:
    html {
    filter: invert(1) hue-rotate(180deg)
    img, etc, etc, etc {
    filter: invert(1) hue-rotate(180deg)
    }
    }
    on the basis that img is a child of (and so relative to) html, therefore automatically switching it back for all img tags?? Or is that completely wrong??

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

    I used .dark-mode, .dark-mode *.inverted{ filter: invert(1) hue-rotate(180deg); } instead of doing it in the js on my layout to optimize it a little bit. Great video!

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

      W3C f..ed things up from back when they implemented functionality in CSS via :hover... I swear, you can build a fully functional site without javascripot in many cases, because functionality has been built into both HTML and CSS. Think about tags like / and css like pointer-event: also

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

    Isn't the JS and CSS on Chrome the same as on MS Edge? They both are based on Chromium, right?

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

    Here is what you're looking for @3:52
    :root{ filter: invert(100%)}

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

    Из пальца высосал 12 минут
    Пока костыли пишешь для исправления инвертирования, на выходе столько же кода, как при стандартных подходах выйдет

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

    Just read an article on CSS Tricks on something similar

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

    The javascript code doesnt seem to work

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

    For the .inverted could not we do
    .dark .inverted{
    ....
    }
    Instead of using javascript to apply that

  • @CreativeB34ST
    @CreativeB34ST 3 года назад +3

    The new Microsoft Edge is actually really good right now. Microsoft realized they're bad at making their own browsers so they implemented made one built upon Chromium. It should have same compatibilities as Chrome itself.

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

    i have a doubt, which is apart from this Context, but garry, can you explain, how you bring your speaking thumbnail to the footer of the video, without a square background, but your body shaped crop... I need this badly, Pls HELP

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

    Why not .dark-mode:not(img):not(button *)

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

    why not use the :not() option in CSS?

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

    Please share, how to make skeleton screen on wordpress 🙏

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

    Awesome quick demo.
    Could you share the Bulma video you mentioned at 2:26

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

    Катюха - красава 😘

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

    Instead of applying it twice, you could just apply it once to all elements EXCEPT the ".invert" class elements, using ":not(.invert)"

    • @Anton-cv2ti
      @Anton-cv2ti 3 года назад

      Nope. You would be reverting the color multiple times for nested elements, making a for a real schwifty color scheme.

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

      @@Anton-cv2ti you're saying in the case there's a parent and child that both have the invert class? There's no reason for the child to have that class then.

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

    Just to nit pick, .dark-mode .inverted{ filter....} Would work better than foreach'ing, as you are already adding the class to elements. Great snippet though, didn't know about this one. Thx

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

    The fact that I can not find a single comment pointing out that JS for toggle the "inverted" class is not necessary at all and could be solved using CSS selectors, everyone stopped watching after the trick was revealed :D

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

    Or you could use css variables and switch the colour palette correctly (either with a theme switch or prefers-color-scheme), this hue rotation is just messy 👎🏻

    • @DesignCourse
      @DesignCourse  3 года назад +3

      Right, like I said in the video, it could be useful for a really simple page, or just prototyping.

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

      Or you can change the color of each element with JS... There's plenty of solutions but one line css is really faster...

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

    You could still make this one line if you used the :not() selector. .dark-mode :not(img):not(.inverted){ filter: invert(100%) }

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

    Amazing!

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

    Tip: If you create a file called css/main.css it'll create a folder named css with a file called main.css

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

    “It works in edge!”
    👀 Edge being built in chromium

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

    Heyyy I noticed you have a bass and guitar hanging on your wall. I am new to this channel so I don't know if you answered this. But as a fellow musician who is trying to start his freelance web dev business. What music do you like to play and how often do you play?

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

    He even remembered his own code. Seriously.

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

    Why not just use css's ":not(.invertproof)" instead of js to keep anything you dont want to get inverted?
    Thanks for the content btw👍

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

    its perfect, thanks

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

    body:not(.force-light){
    .....
    }

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

    How to fix It for Firefox

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

    Edge is running on Chromium Engine so anything work on Google Chrome works on Edge.

  • @Sakura-ek6vo
    @Sakura-ek6vo 3 года назад

    Thank you thank you thank you 😭😭😭😭❤️❤️❤️❤️❤️ you saved me ❤️❤️❤️❤️😭😭😭😭🌸🌸🌸