CSS em and rem explained

Sdílet
Vložit
  • čas přidán 1. 06. 2024
  • A look at the CSS units EM and REM, how they work and when you might want to use one over the other!
    First I take a look at some basic examples of both ems and rems, then move onto some more interesting things with buttons and a call to action, as well how we can take advantage of both the em and rem with media queries.
    The way the em unit is calculated actually changes depending on if being used for that element's font-size or if it's being used for any other property, and this can be leveraged in some pretty awesome ways!
    Knowing when to use em vs rem can be a tricky business, but hopefully this video can help put you on the right track!
    Find the Codepen here: codepen.io/kevinpowell/pen/RKdjXe
    --
    New to Sass, or want to step up your game with it? I've got a course just for you: www.kevinpowell.co/learn-sass
    --
    I'm on some other places on the internet too!
    If you'd like a behind the scenes and previews of what's coming up on my CZcams channel, make sure to follow me on Instagram and Twitter.
    Instagram: / kevinpowell.co
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell/

Komentáře • 424

  • @reactmagic2348
    @reactmagic2348 Před 3 lety +268

    Man finally someone gives me a real reason to use “rem” and “em” and explains it in a convincing way. This is why you are the master. Thank you sir

  • @Faiqa-Abbas
    @Faiqa-Abbas Před 4 měsíci +9

    This is really helpful Kevin! Stay blessed!😄
    So if we summarize:
    use *rem* with *font-size* because it always looks at the root or HTML element for *font-size* . So, we don't need to worry about parent-child calculations as with *em* .
    use *em* with *padding* as em will adjust the padding based on the font-size of that element.
    use *rem* with *margin* if you want consistent space among all the adjacent elements.

  • @chrisclinejax
    @chrisclinejax Před 5 lety +118

    you have a gift for making that "ah that makes sense" moment happen

    • @mohamedelidrissi9914
      @mohamedelidrissi9914 Před 2 lety +2

      every damn time i think "why would i ever need that" then i go "AH!"

  • @pemadechen9901
    @pemadechen9901 Před 5 lety +258

    Sir, you are a blessing to us..

  • @franksolinsky2365
    @franksolinsky2365 Před rokem +30

    Hi Kevin,
    I'm just finishing day 2 of the course and I wanted to take a moment to thank you for offering this free content. I have been really struggling to understand responsive design and decided to find a way to make it click. Likewise, I have always found your content helpful and concise before, making it easy to turn to you for instruction now. I have got to say, in the two short lessons so far, it's already making so much more sense. You're the best!

  • @SazikimiJaeger
    @SazikimiJaeger Před 5 lety +92

    Seriously having nightmares with rems and ems. But no more. The nightmare is over Thanks to you. Great tutorial again, right up to the point along with simple explanation. 😀😀😀

  • @avimishra8263
    @avimishra8263 Před rokem +2

    I am watching this after 5 years since the video got released and still its the best video on rem and em in youtube

  • @Anonymouspock
    @Anonymouspock Před 5 lety +108

    That is some extremely interesting colour grading at the start.

  • @daniamsalem
    @daniamsalem Před 4 lety +38

    I'm on your Conquering Responsive Layouts course and I learned so much from this one video. At the agency where I build WordPress templates, I'm used to building websites for desktops and then using media queries to resize designs for mobile devices. But now, my whole mindset has changed. Your use of media queries to change `html` font size with minimal changes to child elements and their font size and padding is epic!

  • @jakeperl5857
    @jakeperl5857 Před 2 lety +3

    5 yrs on and the best explanation I've seen on this topic... for the first time I finally get it...thank you!

  • @AshishSingh-he2qo
    @AshishSingh-he2qo Před 4 měsíci +1

    1. Font-size: rem to fixed
    2. Padding: em because it see the element font size
    3. Margin: rem to fixed the margin gap

  • @taariqq
    @taariqq Před 4 lety +9

    Small chunks of information, followed by enough practice, makes the concept stick.
    Thanks for that 'drip content' style course on responsive layouts. It is helping immensely!

  • @lennoxgilbert4968
    @lennoxgilbert4968 Před 2 lety +2

    You are truly a godsend; such clear and succinct explanations and examples. Thank you so much, Kevin!

  • @merictunc
    @merictunc Před měsícem

    Finally, someone has made a clean and practical explanation of what REM and EM. 🎉 thanks for sharing

  • @flaminggasolineinthedarkne4

    When I was struggling with css3 margin and padding, I wish I would have watched this video at that time. That's so amazing and informative sir Kevin Powell. You are a genius.

  • @ericka606
    @ericka606 Před 2 měsíci

    Thank you Kevin, taking your responsive layouts course now and wanted to be thorough. Had an aha moment so glad I came to check this out.

  • @johnnysausage835
    @johnnysausage835 Před 5 lety

    This channel is a gift, superb job thanks a lot Kevin

  • @abdullahzeeshan4516
    @abdullahzeeshan4516 Před 4 lety

    I'm new to this channel and i just love that different css things that not much of the people explain are explained by him (just loved it)

  • @JohnMcCormack
    @JohnMcCormack Před 5 lety

    Excellent and thorough explanation of em versus rem. Thank you.

  • @aneidlin
    @aneidlin Před 4 lety +7

    You and your videos are probably the best teacher and resources I've found to really learn and understand what's happening with CSS. What they teach you in school or in books doesn't explain the nuances that you're going to need to know when you're developing real-world applications. Thank you so much for everything you do and for being such a boon to those of us who are looking to level up our skills quickly while also developing that deeper understanding!

  • @mattshirlaw3092
    @mattshirlaw3092 Před rokem

    Very underrated video… still to this day the best explanation of em/rem I’ve seen. Thank you 🙏

  • @Doraphobic
    @Doraphobic Před rokem

    Kevin your content is SO HELPFUL!

  • @petarkolev6928
    @petarkolev6928 Před 2 lety +2

    Kevin, you are amazing mentor! Each video of yours gives me "aha" moment and the insane to this is I code for 4 years now and still I have so many misunderstandings and you bring brightness to me with every video

  • @marie-elizeventer7080

    Thanks! I have been watching video's about EM and REM forever, and I never understood it until today. Great tutorial, great examples.

  • @GauthamHC99
    @GauthamHC99 Před 3 lety +3

    this saves us from media query to a great extent 🙏. Thanks Kevin.

  • @climb.and.wander
    @climb.and.wander Před 2 lety +16

    Great video about explaining the differences between rems and ems. For those, like me, who like to know to what actual pixels the relative values turn into, the computed values in devtools and/or just inspecting an element can give some confidence about that. Another important aspect of giving relative font-sizes is to support accessibility. If a user has different browser settings for default font-size, the font-sizes in pixels won't adapt. These are just some thoughts that came up while watching the video. Some may find it useful. Cheers!

  • @kevinbegin3049
    @kevinbegin3049 Před 3 lety +1

    Thank you for all these tutorials. Every single one rocks! Super helpful!

  • @diegofergusson9113
    @diegofergusson9113 Před 2 lety

    I was seeing your course of responsive with ccs and sir you are amazing, thanks you, you help me a lot !

  • @pika7037
    @pika7037 Před 6 lety +49

    Please make a video on - ::before and ::after ( I really don't understand this thing ) and also make a video on - transform and translateX and translateY and also make a video on absolute, relative position in css and also make a video on linear gradient and also make a video on - Explain overflow concepts and Sorry for so much videos but Kevin you explain very well and you are the world's best teacher in the world...I love my teacher Kevin ( Honestly from heart ) - I love you and thank you so much

    • @KevinPowell
      @KevinPowell  Před 6 lety +30

      Glad you're enjoying my videos Mahendra! Don't watch too many of them at once, take some time to practice what you're learning! I actually have quite a few of your suggestions on my list! A video on ::before and ::after should be coming out in a few weeks, and I have something for absolute and relative as well. Thanks for the suggestions though, I'll add the others to my list :)

  • @dishantsharma8614
    @dishantsharma8614 Před 3 lety

    Such an amazing explanation of em vs rem. great job sir.

  • @memoryman51
    @memoryman51 Před 4 lety +4

    I finally feel like I have a handle on this topic. Great explanation. Thanks!

  • @guillermoandradaFSD
    @guillermoandradaFSD Před 3 lety +1

    It's just amazing... You explain us, and it's easy to understand everything.
    Thank you so much... Love it...

  • @bekjohansson3016
    @bekjohansson3016 Před 3 lety

    Outstanding job on explaining, em and rem and why and how to use them!

  • @start-media
    @start-media Před 2 lety +15

    This is the best explanation I’ve seen so far. Watching your tips saves years of lifetime 😊

    • @Tridentus
      @Tridentus Před rokem +3

      I can't believe I even ever tried to build anything ever without watching this video. How stupid was that? 😆
      17 minutes that could have saved me weeks of my life.

  • @chanm01
    @chanm01 Před 4 lety +2

    ...okay. That single media-query thing at the end sold me. I can see that being used all the time. 😮

  • @ElenaYavorskaya
    @ElenaYavorskaya Před 3 měsíci +1

    Amazingly useful video!! Thank you sooooo much!!!

  • @FredSq
    @FredSq Před 15 hodinami

    this is incredible, even after 7 years

  • @aspsa6246
    @aspsa6246 Před 3 lety

    Well done, Kevin. Very concise and clear.

  • @SamCrowetheCreativeCrowe

    Experiencing some real stress with a "simple" landing page build out for an existing page. In media query hell yet but finding this and the 21 day challenge course to be very rewareding and useful. Kevin Powell is a trusted resource fo CSS. I am a big fan and even bought the hoodies!

  • @iDarkBladei2
    @iDarkBladei2 Před 4 lety

    Such a good video! Now i not only understand the difference between them, but also when should or shouldn't i use each of them. Very helpful, thank you :)

  • @surendrababuchalla
    @surendrababuchalla Před 2 lety +1

    First time saw practical use of em and rem in case study example. Thank you sir

  • @mkajiwala1
    @mkajiwala1 Před 3 lety

    great explation ,just started your course -challenge , this presentation will certainly helpful ! this speaks your experience of so many years......

  • @l_bonza7555
    @l_bonza7555 Před 6 lety +33

    Best explanation! Keep it up. Love your way of explaining things

    • @KevinPowell
      @KevinPowell  Před 6 lety +2

      Thanks so much, glad you liked the vid :)

  • @rpf23543
    @rpf23543 Před rokem

    Awesome! You’re really doing the best html, css Tutorials out there. Thank you so much!!!

  • @doctorartiste2905
    @doctorartiste2905 Před rokem

    CRL - Day 2 CSS em and rem explained! Learning so much already. TY KEVIN!!!

  • @dabbopabblo
    @dabbopabblo Před rokem

    The only knowledge anyone needs from this is within the first 50 seconds. You all obsess over how thankful you are to have all these opinions on how and why you should use different aspects of css when the only reason he’s able to give you those opinions is he put in the trial and error of figuring out css from not knowing anything and just using what you see works to picking up thing by thing and applying it to his workflow in a way more natural way then trying to jerry rig multiple peoples coding styles together in your learning process

  • @shecodes94623
    @shecodes94623 Před 2 lety

    This channel has an amazing energy and awesome content... thankssss

  • @z40140110
    @z40140110 Před 2 lety

    simple but extremely concept , thank you so much for delivering it

  • @amrobbie
    @amrobbie Před 2 lety

    Amazingly helpful - thank you Kevin!

  • @hakanviajando
    @hakanviajando Před rokem +1

    You are a CSS geniues, I'm following the Conquest Responsive Layouts course and thinking about that html and css is responsive by default, but we break it with rules is amazing. great perspective. Thanks for all the work.

  • @RaoulUnger
    @RaoulUnger Před 4 lety

    Excellent video, thanks for clarifying this once and for all. The codepen is really helpful too!

  • @Alexis-fw5zj
    @Alexis-fw5zj Před rokem

    Thank you so much! I really appreciate you sharing your knowledge and making things easier to understand

  • @aurimasgedvilas4460
    @aurimasgedvilas4460 Před 6 měsíci

    This video helped me greatly, thank you Kevin :)

  • @clevermissfox
    @clevermissfox Před 8 měsíci

    Cant wait to actually understand when to use which... love this channel!

  • @GGdevelopment
    @GGdevelopment Před 4 lety +24

    I've gotten 3 recommended videos from from you by CZcams and they were what I was looking for. Haha
    +1 sub

    • @KevinPowell
      @KevinPowell  Před 4 lety +5

      Welcome aboard! Glad that CZcams is pointing you in the right direction (though it's also sometimes a bit scary, lol)

  • @Developism
    @Developism Před dnem

    You nailed the explanation!

  • @JocelynAlsdorf
    @JocelynAlsdorf Před 11 měsíci

    6 years later and this content is still so helpful :)

  • @RahulSharma-ox6se
    @RahulSharma-ox6se Před 3 lety

    That was super helpful. Thank you so much, Kevin!!

  • @Razax7
    @Razax7 Před rokem

    You made it extremely easy for me. Thank you!

  • @darabumdarabum
    @darabumdarabum Před 2 lety

    I have been using pixels and a thousand media queries, one for each element and subelement, in order to scale the fonts up and down. No more. I was always afraid of using Ems and Rems and this is the first time I feel like I understand them. Thank you!

  • @fabriziofilograna6498
    @fabriziofilograna6498 Před 3 lety

    this is going to change my game! thank you Kevin

  • @stormbytes
    @stormbytes Před rokem

    Very well explained. Thank you!

  • @jawad9757
    @jawad9757 Před 4 lety

    I never took the time to understand em and rem and I've never bothered to use them so thank you for creating this video

  • @mizanurrahmankhan692
    @mizanurrahmankhan692 Před 5 lety +1

    Man, I have fallen in love with your channel. Thanks for making awesome videos.

    • @KevinPowell
      @KevinPowell  Před 5 lety +2

      Glad that you're enjoying my content!

  • @abdulraffy5398
    @abdulraffy5398 Před 2 lety

    Useful video. I finally get a sound reason to use em and rem. I have used px all the time but from now on I will use em and rem

  • @arigrafik
    @arigrafik Před rokem

    Great way to explain em and rem Thank you so much!

  • @lmd4881
    @lmd4881 Před 2 lety

    oh my goodness!!!!!!!!!! BE GONE dubious-looking-buttons -on-small-screen-sizes I flat out had no idea that ems are the magic behind perfect buttons, thank you soooo much Kevin :) :)

  • @goutamprasadmohapatra6363

    That's a very detailed explanation thankyou sir

  • @marcocarcini
    @marcocarcini Před 2 lety

    Very clear explanation

  • @benzflynn
    @benzflynn Před 3 lety

    15:02 Real cool flick around there - saves us a bunch of time and misery changing a lot of font-sizes through a page. Just like old Jimbo Rockford at the wheel of his Firebird.

  • @markbarton6845
    @markbarton6845 Před 3 lety

    Great video Kevin, thanks!

  • @KenzoArts
    @KenzoArts Před 4 lety +1

    Hello Kevin ! I like your clear explanation on most confusing css properties. Could you please make a video about 'calc' function in CSS, how and when to use it. Thanks

  • @joshcharlottesville
    @joshcharlottesville Před 3 lety +1

    This channel might make me change my life and become a better coder.

  • @sexymeal2427
    @sexymeal2427 Před rokem

    Incredible. Wish I found your css tutorials sooner

  • @juan-pablobotero4609
    @juan-pablobotero4609 Před 3 lety

    You are such a clever guy 💪. Thanks for taking the time to create this video and sharing your knowledge.

  • @ForeverChip03
    @ForeverChip03 Před 4 měsíci +1

    You are the man.
    Good work 👍👍

  • @knotcircle2844
    @knotcircle2844 Před 2 lety +3

    Thanks to this video. I always use rem coz I was in a rush to learn things back then. I now know when to use em instead of rem.
    Some takeaways
    6:41 - the difference of using margins from padding
    12:48 - onto pixels

  • @pupinarvaja
    @pupinarvaja Před 2 lety

    This video made me delete more than 300 lines of code, making my code much more clean and optimized. I came across your channel and I am learning a lot, thank you so so much.

  • @squdge
    @squdge Před 3 lety

    Fantastic resource, thank you.

  • @rojingharooni821
    @rojingharooni821 Před rokem

    you are absolutely the definition of WONDERFULL.good you are on this planet

  • @hulksunil
    @hulksunil Před 3 lety

    Thank you very much for the explanation.

  • @jakke1975
    @jakke1975 Před 2 lety

    Thanks for yet another fantastic explanation.

  • @martunjaykumar752
    @martunjaykumar752 Před 2 lety

    For the 1st time ever, I understood em and rem, how it works.

  • @TheCocoaDaddy
    @TheCocoaDaddy Před 2 lety

    Very useful video!!!! I'm taking the responsive layouts course now and just watched this video! Thanks for posting!!!!! Ok, back to the course. :)

  • @aCitizenJOSerased
    @aCitizenJOSerased Před 3 lety

    Awesome video! Thank you Kevin.

  • @david2am
    @david2am Před 2 lety

    Thanks to you I can understand and apply em and rem, I love to see your videos, God bless you

  • @rontripiano6337
    @rontripiano6337 Před 2 lety

    I am in the middle of learning front-end coding and WOW - I'm was confused. Now, I get it. Thanks, A Lot.

  • @DjCtavia
    @DjCtavia Před 2 lety

    Still very useful content, glad to see that video, never too late!

  • @oncalldev
    @oncalldev Před rokem

    Great explanation.

  • @marinicamashinica
    @marinicamashinica Před rokem

    Excellent explanation with great examples, you're truly a talented lecturer!
    Sorry for bad English and going a bit off-topic, but I'm so excited and motivated after watching this video and having a revelation on CSS units, I just had to share my feelings; you remind me very much of my "live" teacher in my Front-end education program, who is an excellent, knowledgable and passionate top-tier teacher, just like you are; I think it is really challenging to make such great content in such a short time, and still maintaining fantastic feedback from your viewers, or should I say, students, which of course means people are *actually* learning so so very much, and feeling motivated, happy and engaged while going through all these amazing lectures... So you most definitely are succeeding in making CSS less frustrating, more exciting and even "fall-in-loveable"! 😄 To you and all other developers who are so dedicated to share their knowledge with the world, THANK YOU from the bottom of my heart, you are the greatest, and you are making the teaching profession proud!

  • @bischoffdev
    @bischoffdev Před 2 lety +1

    I finally understand it now! Thank you!

  • @leonardocr506
    @leonardocr506 Před 2 lety

    masterfully explained

  • @jelenatrifkovic5567
    @jelenatrifkovic5567 Před rokem

    Nice explanation!

  • @alejandrorestrepo2978
    @alejandrorestrepo2978 Před 6 lety +3

    thank you so much for your video, it really helped me put things into perspective. The use of ems and rems really makes a difference to the mobile friendly design and I've never seen it explain as well as in this video, so thanks for posting this video..

  • @anthonysmith7913
    @anthonysmith7913 Před 4 měsíci +1

    Man, you are a hero!

  • @philippaubert2947
    @philippaubert2947 Před 2 lety

    Thanks for doing this :) I'm learning so much !!

  • @terrilence2
    @terrilence2 Před 2 lety

    Thanks for that great explanation.

  • @tapaschakraborty4372
    @tapaschakraborty4372 Před rokem

    nice informative video Kevin

  • @mauricioramirez2855
    @mauricioramirez2855 Před 2 lety

    Thank you so much Kevin, very useful the video!!

  • @saurabh75prakash
    @saurabh75prakash Před 2 lety

    Awesome tutorial! thanks.