CSS em and rem explained

  Рет қаралды 379,460

Kevin Powell

Kevin Powell

Күн бұрын

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 KZfaq channel, make sure to follow me on Instagram and Twitter.
Instagram: / kevinpowell.co
Twitter: / kevinjpowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell/

Пікірлер: 427
@reactmagic2348
@reactmagic2348 3 жыл бұрын
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 5 ай бұрын
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 5 жыл бұрын
you have a gift for making that "ah that makes sense" moment happen
@mohamedelidrissi9914
@mohamedelidrissi9914 2 жыл бұрын
every damn time i think "why would i ever need that" then i go "AH!"
@anandcherian.585
@anandcherian.585 13 күн бұрын
You are right! He does have that gift!
@pemadechen9901
@pemadechen9901 5 жыл бұрын
Sir, you are a blessing to us..
@ne9835
@ne9835 3 жыл бұрын
Agreed!!
@jcpartri
@jcpartri 3 жыл бұрын
I agree. :-)
@mayurravindra9433
@mayurravindra9433 3 жыл бұрын
Indeed😌
@avimishra8263
@avimishra8263 Жыл бұрын
I am watching this after 5 years since the video got released and still its the best video on rem and em in youtube
@franksolinsky2365
@franksolinsky2365 Жыл бұрын
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!
@Anonymouspock
@Anonymouspock 5 жыл бұрын
That is some extremely interesting colour grading at the start.
@SazikimiJaeger
@SazikimiJaeger 5 жыл бұрын
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. 😀😀😀
@KevinPowell
@KevinPowell 5 жыл бұрын
Glad I could help!
@rashujain6813
@rashujain6813 2 жыл бұрын
@@KevinPowell talk about deep nested comments
@tnblackdragongamingofficia6163
@tnblackdragongamingofficia6163 3 ай бұрын
@@rashujain6813 this is kevin powell alt account - will do
@taariqq
@taariqq 4 жыл бұрын
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!
@flaminggasolineinthedarkne4
@flaminggasolineinthedarkne4 2 жыл бұрын
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.
@daniamsalem
@daniamsalem 4 жыл бұрын
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!
@eduardoomar8213
@eduardoomar8213 2 жыл бұрын
Instablaster...
@aneidlin
@aneidlin 4 жыл бұрын
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!
@petarkolev6928
@petarkolev6928 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
@lennoxgilbert4968
@lennoxgilbert4968 2 жыл бұрын
You are truly a godsend; such clear and succinct explanations and examples. Thank you so much, Kevin!
@jakeperl5857
@jakeperl5857 2 жыл бұрын
5 yrs on and the best explanation I've seen on this topic... for the first time I finally get it...thank you!
@start-media
@start-media 2 жыл бұрын
This is the best explanation I’ve seen so far. Watching your tips saves years of lifetime 😊
@Tridentus
@Tridentus Жыл бұрын
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.
@GauthamHC99
@GauthamHC99 3 жыл бұрын
this saves us from media query to a great extent 🙏. Thanks Kevin.
@climb.and.wander
@climb.and.wander 2 жыл бұрын
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!
@abdullahzeeshan4516
@abdullahzeeshan4516 4 жыл бұрын
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)
@mattshirlaw3092
@mattshirlaw3092 Жыл бұрын
Very underrated video… still to this day the best explanation of em/rem I’ve seen. Thank you 🙏
@GGdevelopment
@GGdevelopment 4 жыл бұрын
I've gotten 3 recommended videos from from you by KZfaq and they were what I was looking for. Haha +1 sub
@KevinPowell
@KevinPowell 4 жыл бұрын
Welcome aboard! Glad that KZfaq is pointing you in the right direction (though it's also sometimes a bit scary, lol)
@memoryman51
@memoryman51 4 жыл бұрын
I finally feel like I have a handle on this topic. Great explanation. Thanks!
@marie-elizeventer7080
@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.
@chanm01
@chanm01 4 жыл бұрын
...okay. That single media-query thing at the end sold me. I can see that being used all the time. 😮
@JocelynAlsdorf
@JocelynAlsdorf Жыл бұрын
6 years later and this content is still so helpful :)
@kevinbegin3049
@kevinbegin3049 3 жыл бұрын
Thank you for all these tutorials. Every single one rocks! Super helpful!
@JohnMcCormack
@JohnMcCormack 5 жыл бұрын
Excellent and thorough explanation of em versus rem. Thank you.
@ericka606
@ericka606 3 ай бұрын
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 5 жыл бұрын
This channel is a gift, superb job thanks a lot Kevin
@SamCrowetheCreativeCrowe
@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!
@l_bonza7555
@l_bonza7555 7 жыл бұрын
Best explanation! Keep it up. Love your way of explaining things
@KevinPowell
@KevinPowell 7 жыл бұрын
Thanks so much, glad you liked the vid :)
@knotcircle2844
@knotcircle2844 2 жыл бұрын
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
@jawad9757
@jawad9757 4 жыл бұрын
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
@darabumdarabum
@darabumdarabum 3 жыл бұрын
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!
@FFergussond
@FFergussond 2 жыл бұрын
I was seeing your course of responsive with ccs and sir you are amazing, thanks you, you help me a lot !
@Doraphobic
@Doraphobic Жыл бұрын
Kevin your content is SO HELPFUL!
@guillermoandradaFSD
@guillermoandradaFSD 3 жыл бұрын
It's just amazing... You explain us, and it's easy to understand everything. Thank you so much... Love it...
@iDarkBladei2
@iDarkBladei2 4 жыл бұрын
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 :)
@mizanurrahmankhan692
@mizanurrahmankhan692 6 жыл бұрын
Man, I have fallen in love with your channel. Thanks for making awesome videos.
@KevinPowell
@KevinPowell 6 жыл бұрын
Glad that you're enjoying my content!
@hakanviajando
@hakanviajando Жыл бұрын
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.
@surendrababuchalla
@surendrababuchalla 2 жыл бұрын
First time saw practical use of em and rem in case study example. Thank you sir
@bekjohansson3016
@bekjohansson3016 3 жыл бұрын
Outstanding job on explaining, em and rem and why and how to use them!
@clevermissfox
@clevermissfox 9 ай бұрын
Cant wait to actually understand when to use which... love this channel!
@rpf23543
@rpf23543 Жыл бұрын
Awesome! You’re really doing the best html, css Tutorials out there. Thank you so much!!!
@dishantsharma8614
@dishantsharma8614 3 жыл бұрын
Such an amazing explanation of em vs rem. great job sir.
@benzflynn
@benzflynn 3 жыл бұрын
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.
@ElenaYavorskaya
@ElenaYavorskaya 4 ай бұрын
Amazingly useful video!! Thank you sooooo much!!!
@RaoulUnger
@RaoulUnger 4 жыл бұрын
Excellent video, thanks for clarifying this once and for all. The codepen is really helpful too!
@z40140110
@z40140110 2 жыл бұрын
simple but extremely concept , thank you so much for delivering it
@alejandrorestrepo2978
@alejandrorestrepo2978 6 жыл бұрын
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..
@KevinPowell
@KevinPowell 6 жыл бұрын
No problem at all!
@aspsa6246
@aspsa6246 3 жыл бұрын
Well done, Kevin. Very concise and clear.
@shecodes94623
@shecodes94623 2 жыл бұрын
This channel has an amazing energy and awesome content... thankssss
@fabriziofilograna6498
@fabriziofilograna6498 3 жыл бұрын
this is going to change my game! thank you Kevin
@aurimasgedvilas4460
@aurimasgedvilas4460 7 ай бұрын
This video helped me greatly, thank you Kevin :)
@mkajiwala1
@mkajiwala1 3 жыл бұрын
great explation ,just started your course -challenge , this presentation will certainly helpful ! this speaks your experience of so many years......
@RahulSharma-ox6se
@RahulSharma-ox6se 3 жыл бұрын
That was super helpful. Thank you so much, Kevin!!
@doctorartiste2905
@doctorartiste2905 Жыл бұрын
CRL - Day 2 CSS em and rem explained! Learning so much already. TY KEVIN!!!
@Razax7
@Razax7 Жыл бұрын
You made it extremely easy for me. Thank you!
@markbarton6845
@markbarton6845 3 жыл бұрын
Great video Kevin, thanks!
@amrobbie
@amrobbie 2 жыл бұрын
Amazingly helpful - thank you Kevin!
@anthonysmith7913
@anthonysmith7913 5 ай бұрын
Man, you are a hero!
@abdulraffy5398
@abdulraffy5398 2 жыл бұрын
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
@rontripiano6337
@rontripiano6337 2 жыл бұрын
I am in the middle of learning front-end coding and WOW - I'm was confused. Now, I get it. Thanks, A Lot.
@stormbytes
@stormbytes Жыл бұрын
Very well explained. Thank you!
@mtouseefwaqas
@mtouseefwaqas Ай бұрын
You nailed the explanation!
@Alexis-fw5zj
@Alexis-fw5zj Жыл бұрын
Thank you so much! I really appreciate you sharing your knowledge and making things easier to understand
@AshishSingh-he2qo
@AshishSingh-he2qo 5 ай бұрын
1. Font-size: rem to fixed 2. Padding: em because it see the element font size 3. Margin: rem to fixed the margin gap
@CodingCompanion-zr6vu
@CodingCompanion-zr6vu 4 ай бұрын
em is basically there to fu(k things up
@joshcharlottesville
@joshcharlottesville 3 жыл бұрын
This channel might make me change my life and become a better coder.
@rojingharooni821
@rojingharooni821 Жыл бұрын
you are absolutely the definition of WONDERFULL.good you are on this planet
@ForeverChip03
@ForeverChip03 5 ай бұрын
You are the man. Good work 👍👍
@KenzoArts
@KenzoArts 4 жыл бұрын
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
@sexymeal2427
@sexymeal2427 Жыл бұрын
Incredible. Wish I found your css tutorials sooner
@PerryCodes
@PerryCodes 2 жыл бұрын
I found it perfect that the surprise width changing slightly @ 5:40 was due to em instead of rem being used for the margin/padding size for .col :)
@squdge
@squdge 3 жыл бұрын
Fantastic resource, thank you.
@pika7037
@pika7037 6 жыл бұрын
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 6 жыл бұрын
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 :)
@juan-pablobotero4609
@juan-pablobotero4609 3 жыл бұрын
You are such a clever guy 💪. Thanks for taking the time to create this video and sharing your knowledge.
@leonardocr506
@leonardocr506 2 жыл бұрын
masterfully explained
@DjCtavia
@DjCtavia 2 жыл бұрын
Still very useful content, glad to see that video, never too late!
@merictunc
@merictunc 2 ай бұрын
Finally, someone has made a clean and practical explanation of what REM and EM. 🎉 thanks for sharing
@subhasrini2706
@subhasrini2706 Жыл бұрын
One of the most underrated channels about learning web dev or atleast designing using CSS
@BlurryBit
@BlurryBit 3 жыл бұрын
Thanks man. I needed a refresher. :)
@KevinPowell
@KevinPowell 3 жыл бұрын
You're welcome 😊
@DavidElstob73
@DavidElstob73 4 жыл бұрын
It's super easy once you get it. Thanks, Kevin. :)
@arigrafik
@arigrafik Жыл бұрын
Great way to explain em and rem Thank you so much!
@jakke1975
@jakke1975 2 жыл бұрын
Thanks for yet another fantastic explanation.
@TheCocoaDaddy
@TheCocoaDaddy 2 жыл бұрын
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 3 жыл бұрын
Awesome video! Thank you Kevin.
@OnTheArchipelago
@OnTheArchipelago 7 жыл бұрын
Cool video, cleared up a lot!
@KevinPowell
@KevinPowell 7 жыл бұрын
Great to hear, I'm glad it helped!
@marcocarcini
@marcocarcini 2 жыл бұрын
Very clear explanation
@JJ29621
@JJ29621 7 жыл бұрын
Thanks heaps Kevin, I can finally start using em's in my projects now. Could never understand them before.
@KevinPowell
@KevinPowell 7 жыл бұрын
That just makes my day James, I'm so happy I could help! You won't know how you worked without them once you get used to it!
@carlosrangel4500
@carlosrangel4500 16 күн бұрын
Came here from "CSS Demystified", great insights in CSS!
@bischoffdev
@bischoffdev 2 жыл бұрын
I finally understand it now! Thank you!
@goutamprasadmohapatra6363
@goutamprasadmohapatra6363 2 жыл бұрын
That's a very detailed explanation thankyou sir
@terrilence2
@terrilence2 3 жыл бұрын
Thanks for that great explanation.
@jelenatrifkovic5567
@jelenatrifkovic5567 Жыл бұрын
Nice explanation!
@micaelabalza7592
@micaelabalza7592 3 жыл бұрын
OMG never better explained, thank you!
@oncalldev
@oncalldev Жыл бұрын
Great explanation.
@david2am
@david2am 2 жыл бұрын
Thanks to you I can understand and apply em and rem, I love to see your videos, God bless you
@FrenchinPlainSight
@FrenchinPlainSight 5 жыл бұрын
Thanks man. This is really clear. It's gonna take some playing around to really sink in but I can see awesome benefits to this. Do you use percentages for widths and heights or is there still a case for using ems, rems, px in responsive design?
@truthhorizon5851
@truthhorizon5851 3 жыл бұрын
for width and heights use % or vh and vw
@philippaubert2947
@philippaubert2947 3 жыл бұрын
Thanks for doing this :) I'm learning so much !!
@dilanmjayawardena5894
@dilanmjayawardena5894 11 ай бұрын
this really helps all the time
Avoid These 5 Awful CSS Mistakes
20:42
Kevin Powell
Рет қаралды 190 М.
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31
LOVE LETTER - POPPY PLAYTIME CHAPTER 3 | GH'S ANIMATION
00:15
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Why you shouldn't set font-sizes using em
13:42
Kevin Powell
Рет қаралды 124 М.
Learn CSS Subgrid in 14 minutes
14:19
Slaying The Dragon
Рет қаралды 60 М.
5 simple tips to making responsive layouts the easy way
15:54
Kevin Powell
Рет қаралды 748 М.
Learn CSS Units In 8 Minutes
8:48
Web Dev Simplified
Рет қаралды 225 М.
Avoid these 5 beginner CSS mistakes
21:38
Kevin Powell
Рет қаралды 74 М.
You can do that with margins?
14:40
Kevin Powell
Рет қаралды 185 М.
5 CSS mistakes that I see way too often
19:03
Kevin Powell
Рет қаралды 359 М.
CSS Subgrid Layouts Are Here!
9:09
Dmitry Mayorov
Рет қаралды 7 М.
Learn flexbox the easy way
34:04
Kevin Powell
Рет қаралды 686 М.
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31