px vs rem: what to use for font-size in your CSS

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 11. 06. 2024
  • đŸ”„ My course: Responsive Design for Beginners! coder-coder.com/responsive/
    đŸ’» Become a full-stack web dev with Zero to Mastery: academy.zerotomastery.io/a/af...
    In this video I talk about why I use the rem unit instead of px (pixels) for font-size in my CSS styles. And I show you how I use rems and convert them to px in my Sass/SCSS workflow!
    0:00 - intro
    0:48 - how to change base font size in the browser
    1:45 - font-size computed with rem units is accessible
    3:32 - using px for font-size is not accessible
    5:09 - why not just use zoom?
    6:24 - absolute and relative units in CSS
    7:22 - how em differs from rem
    11:21 - the 62.5% hack for easier px to rem conversion
    13:32 - I use a Sass function to convert instead
    ____________________________
    SUPPORT THE CHANNEL
    ⭐ Join channel members and get perks: / @thecodercoder
    đŸ‘đŸœ Hit the THANKS button in any video!
    🎹 Get my VS Code theme: marketplace.visualstudio.com/...
    WANT TO LEARN WEB DEV?
    Check out my courses:
    🌟 Responsive Design for Beginners: coder-coder.com/responsive/
    🌟 Gulp for Beginners: coder-coder.com/gulp-course/
    RECOMMENDATIONS
    ⌹ My keyboard-- get 10% off with code THECODERCODER -- vissles.com/?ref=mu96kxst5w
    đŸ’» Other gear -- www.amazon.com/shop/thecoderc...
    📚 My Favorite Books -- coder-coder.com/best-web-deve...
    đŸ“ș My Favorite Courses -- coder-coder.com/best-web-deve...
    đŸ”œ FOLLOW CODER CODER
    Blog -- coder-coder.com/
    Twitter -- / thecodercoder
    Instagram -- / thecodercoder
    #webdevelopment #coding #programming
  • Věda a technologie

Komentáƙe • 111

  • @ngoako
    @ngoako Pƙed 2 lety +34

    I've been learning and forgetting this for forever, it finally clicked! Thank you! I think I'll try the percentage hack for projects sass-less projects and the mixin for when I learn sass😌

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +3

      Awesome!! I'm glad this could help explain things for you 😁

  • @darialysak4591
    @darialysak4591 Pƙed 25 dny

    I am a designer, but you answered to all my questions about rem and em, thanks a lot!

  • @hozay6552
    @hozay6552 Pƙed 2 lety

    Very interesting video! I love how you brought up the function for sass later on. Really helpful! Thank you!

  • @SeniorJuniorDeveloper
    @SeniorJuniorDeveloper Pƙed 2 lety +6

    Love your content, always amazing explanations thanks!

  • @_unknown7_
    @_unknown7_ Pƙed rokem

    Literally answered every question that I had related to the rem vs em explanation. đŸ’—â™„â™„

  • @LifeAtMH41
    @LifeAtMH41 Pƙed 2 lety +5

    After looking at one of your videos, I started using 'em' and rem() fn in my projects. Thanks for these. Especially for that rem() fn.

  • @sebastianmesa6255
    @sebastianmesa6255 Pƙed 2 lety

    Thanks coder coder. this is super helpfully.

  • @jeet4180
    @jeet4180 Pƙed 2 lety +1

    This is really very helpful. Thank you

  • @sornt
    @sornt Pƙed 2 lety

    very good video. thank you. it is something I haven't clear understand before.

  • @shubhamdhage6935
    @shubhamdhage6935 Pƙed 2 lety +2

    you just got a new sub :) thank you for providing amazing content.

  • @ryanwright3965
    @ryanwright3965 Pƙed 2 lety

    Wow. I just discovered your channel. Your videos are awesome. Keep it up!!

  • @themussseee
    @themussseee Pƙed rokem

    I finally understand rem and ems thank you so much

  • @sknadeem340
    @sknadeem340 Pƙed 2 lety +2

    Love your work.... ❀❀Keep making awsem videos...

  • @KentaroxKondo
    @KentaroxKondo Pƙed rokem

    ăšăŠă‚‚ă‚ă‹ă‚Šă‚„ă™ă„ă§ă™ă€‚ă‚ă‚ŠăŒăšă†ă”ă–ă„ăŸă™ïŒ

  • @ammarshorbagy3852
    @ammarshorbagy3852 Pƙed rokem

    Thank you very much, I am from Egypt and the translation helps me a lot 😍

  • @wpxpert98
    @wpxpert98 Pƙed rokem

    This video is really helpful, thank you

  • @babinio7458
    @babinio7458 Pƙed 2 lety +2

    another great tutorial !

  • @ax-coding631
    @ax-coding631 Pƙed 2 lety

    Really helpful, thank you!

  • @malamincamara5939
    @malamincamara5939 Pƙed 6 měsĂ­ci

    Naaa, I’m definitely subscribing to you.
    Your explanation is CLEEEAAAN!

  • @danaharley3565
    @danaharley3565 Pƙed 2 lety +1

    I like the way you explain it to us

  • @itsmenow9870
    @itsmenow9870 Pƙed rokem

    Thanks for the info đŸ’Żâ€ïž

  • @hookerrabbit
    @hookerrabbit Pƙed 2 lety

    New to your channel. Great content. equally great presentation. Thank you.

  • @imkir4n
    @imkir4n Pƙed 2 lety +1

    Good info thanks Jessica ❀

  • @adrianmin713
    @adrianmin713 Pƙed 2 lety +3

    As always quality video! I was just wondering could we just set the base font size to 10px instead of 62.5%? Thank you for the amazing content.

  • @salaheddineaksaim4348
    @salaheddineaksaim4348 Pƙed 2 lety

    Really helpful, thank you!.

  • @simonehenry9041
    @simonehenry9041 Pƙed 2 lety

    thank you for this! finally clicked in my brain

  • @bikalrai8987
    @bikalrai8987 Pƙed 2 lety

    one vid to make me subscribe to your channel, first vid i have watched of yours, thanks for the detailed explanations

  • @iamkhenny_07
    @iamkhenny_07 Pƙed 7 měsĂ­ci

    Wow amazing stuff 😊

  • @efthymiosn3381
    @efthymiosn3381 Pƙed 2 lety +1

    Awesome! Thanks a lot!

  • @bryankersten54
    @bryankersten54 Pƙed 2 lety

    Awasome video! thank you so much! :D

  • @immathiasyde
    @immathiasyde Pƙed 2 lety +4

    Em's could be used in such a manner that two text elements differ in ems, and have their common parent element to specify its font size in rem's. Like having a title to be double the size of a paragraph.

  • @alpinelux407
    @alpinelux407 Pƙed 2 lety +3

    Thank you so much for making videos for us, will you also gonna teach backend in this channel in future?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +4

      I've done mainly frontend in my career, and only a little backend, so I will most likely not do much backend stuff, unless I start learning it myself 😅 Thanks for watching!

  • @joeariaratne8426
    @joeariaratne8426 Pƙed 2 lety

    Don't skip the ads guys.. needs all the support she can get ...

  • @alimohammad1593
    @alimohammad1593 Pƙed 2 lety

    Okay.,after 100years later,,We got your special video❀❀❀

  • @jabeztadesse
    @jabeztadesse Pƙed 11 měsĂ­ci

    Responsive font is just a must! Specially if you're using clamp it get's rid of all the font "jump" issues

  • @s_liyarli
    @s_liyarli Pƙed 2 lety

    it helped me a lot, love from Azerbaijan

  • @jsbitswithbill8765
    @jsbitswithbill8765 Pƙed 2 lety +1

    That rem() fn is a great idea!

  • @alphatras4573
    @alphatras4573 Pƙed 2 lety

    Thank you very much!

  • @fedestock1815
    @fedestock1815 Pƙed 5 dny

    Thank you!

  • @victorcesarquispeatencio3290

    Amazing đŸ€©

  • @Basic-computer-ai
    @Basic-computer-ai Pƙed 2 lety

    I love your teaching

  • @FilipCodes
    @FilipCodes Pƙed 2 lety

    Very usefull vid 😁

  • @heheboi812
    @heheboi812 Pƙed 2 lety +1

    Hello, in a recent project I did in which I used px, increasing the text size in Chrome on my phone is still scaling the font size even though its in pixels! Any thoughts?

  • @maissendeveloper
    @maissendeveloper Pƙed rokem +1

    thanks for your great videos !! but i'm wondering why we don't use 10px directly instead of 62.5% ?? and what if the default font size is not set to 16px, won't the 62.5% be useless ?

  • @ArielBerloto
    @ArielBerloto Pƙed 2 lety

    You're awesome!

  • @RameshKumar-mv3jd
    @RameshKumar-mv3jd Pƙed 2 lety +13

    With the HTML percentage "hack", couldn't you set it to 6.25% and eliminate the need to divide the final rem units by 10?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +2

      omg I have never considered that! I actually can't think of a reason why that wouldn't work. will have to research that!

    • @RameshKumar-mv3jd
      @RameshKumar-mv3jd Pƙed 2 lety +3

      @@TheCoderCoder awesome, I hope it works

    • @aftabhussain3986
      @aftabhussain3986 Pƙed rokem

      I didn't get it can you elaborate please

    • @chukwudiconfidence3195
      @chukwudiconfidence3195 Pƙed 8 měsĂ­ci

      I am having a problem with mine

  • @sako4822
    @sako4822 Pƙed 2 lety

    Very interesting video!.
    Really helpful, thank you!.

  • @brymstoner
    @brymstoner Pƙed rokem +1

    it's cool. i understand the different units. but because of the unnecessary maths, i find it much easier to just use px. remove the guesswork altogether.

  • @chiaza7735
    @chiaza7735 Pƙed 2 lety +1

    CSS Queen 🏅

  • @dmraushan
    @dmraushan Pƙed rokem +2

    62.5% hack was amazing 😂

  • @joefads5040
    @joefads5040 Pƙed 2 lety +7

    I've been using rem for paddings and margins (alongside fonts), but when scaling the browser font size up the paddings/margins scale to much causing sentences to be broken up onto multiple lines to the point where it feels like a worse experience/un-readable. Any thoughts on this?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +1

      hmm, in that case perhaps you could try using px to set the padding and margin so they will always stay the same?

    • @joefads5040
      @joefads5040 Pƙed 2 lety

      Ahh I'm so stoked you replied thank you! 😁 Yeah I was reading what seems like the only aritlce on medium saying not to using rem/em for layouts. I'm really leaning towards updating my blog layout rem values over to px values. Feels like a zoomed in experience rather than just a visual text aid. BTW I loved the rem sass mixin/fn!! 😍 I'm a massive fan of accessibility and sass, so I really enjoyed this video 😊

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +2

      Cool đŸ‘đŸŒ I'll have to research what units are recommended for padding and margin, px might be better for some things!

  • @Coder-Journey
    @Coder-Journey Pƙed 2 lety

    You're the best

  • @funformic997
    @funformic997 Pƙed 2 lety +2

    You type code so I do not see, please your zoom display

  • @mohammedlayes9248
    @mohammedlayes9248 Pƙed 2 lety

    Hi! If you don't mind me asking, what does font-size: 100% do, please?

  • @blackarchiteck4226
    @blackarchiteck4226 Pƙed 2 lety

    Just found your page today love ❀ your work and content. Just sub too

  • @3101leonardo
    @3101leonardo Pƙed 2 lety

    Hi! I know you get this question a lot, but what is this theme you are using? I really want this extension lol

  • @ChristopherClaudioSkierka

    Hi there, you are nice to listen too when you explain things. Can you please tell me at 8.07 min in the video for example is the screen split with vs code on left and is the right side devtools? also how did you split your screen like that? many thanks in advance

    • @Troyzhen
      @Troyzhen Pƙed rokem

      The three dots in the top right of devtools (which is on the right side) you’ll see options on where to dock your dev tools window.

  • @coderjaber
    @coderjaber Pƙed rokem

    Jessica when u will publish Responsive Design for Beginners course ?

  • @banjo4856
    @banjo4856 Pƙed 15 dny

    My question here is, does this rem and em matterrs in padding and margin as well, or it's only useful for font-sizing

  • @AhmedABD0077
    @AhmedABD0077 Pƙed rokem

    So for padding and margin ..etc can I use rems cuz it is more easy ?

  • @topicsmixer1107
    @topicsmixer1107 Pƙed 2 lety +1

    what is the tip u should give who is learning react :)

  • @ankurvishwakarma8731
    @ankurvishwakarma8731 Pƙed měsĂ­cem

    Can we also use rem for width and height?

  • @justamongus7541
    @justamongus7541 Pƙed 2 lety

    Ok now jessica is being consistent 😅😆

  • @cutipets8706
    @cutipets8706 Pƙed 2 lety

    I think for the padding and margin things gets dif?

  • @thedeveloper9896
    @thedeveloper9896 Pƙed 2 lety +2

    You Look like my teacher 😂 also thank you I will start using rem!

  • @fatesteyneit2990
    @fatesteyneit2990 Pƙed 2 lety

    is it wrong to just define the size on the body so you could use em everywhere? or am I missing something

  • @ahmedragab7934
    @ahmedragab7934 Pƙed 2 lety +2

    ❀❀❀

  • @bx557
    @bx557 Pƙed 2 lety +1

    Do you use px in any case in your projects or just rems and ems?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +2

      I try to never use px, but sometimes I get lazy and use it for border-radius 😅

  • @zakariakhaled1871
    @zakariakhaled1871 Pƙed 2 lety +1

    I think that u speaking about r.e.m beauty 😭😭

  • @safdardahriwal7503
    @safdardahriwal7503 Pƙed 2 lety

    Hello thank you so much for valuable knowledge .I need your help how can I contact you?

  • @shubhamujjwal328
    @shubhamujjwal328 Pƙed 2 lety

    nice

  • @smerspl7175
    @smerspl7175 Pƙed 8 měsĂ­ci

    Hello! I've some problem with it. While I'm using for example: padding-left: rem(30) padding-right: rem(30) it all works, but if I want to use padding: 0, rem(30) or padding: rem(0), rem(30) it doesn't work, somebody know why?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 8 měsĂ­ci

      You don't need the commas when using multiple values for "padding". If you want to only set padding-left and padding-right, you can write "padding-inline: rem(30)". Hope this helps!

  • @questific
    @questific Pƙed 2 lety +4

    Thank you so much Jessica đŸ„° 💀

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +3

      Sorry, I think you may have mistaken me with someone else? Not sure who Samantha is 😅

    • @questific
      @questific Pƙed 2 lety +1

      @@TheCoderCoder OMG IM SO SORRY 😭😭😭😭

  • @dmitriikulbaka1862
    @dmitriikulbaka1862 Pƙed 2 lety +1

    Hello! But what if the font in the layout is 12px or 18px?

    • @rravensspace3617
      @rravensspace3617 Pƙed 2 lety +1

      I believe you would do 12px/16px = 0.75rem and 18px/16px = 1.125rem. Because 1 rem = 16px, providing you use html { font-size: 100%;} Hope that is understandable.

    • @dmitriikulbaka1862
      @dmitriikulbaka1862 Pƙed 2 lety +1

      @@rravensspace3617 Yes. I understood. Thanks.

  • @coolemur976
    @coolemur976 Pƙed 2 lety +1

    You should take a look at "CSS px vs rem in 2021 - Use px and Here's Why" on yt

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +1

      I've seen it-- he makes good points about wanting consistency across websites which totally make sense. Ultimately I believe that a feature should behave the way its designed. So I personally prefer to allow the base font-size changing to affect a website text size, since that's what a user is expecting when they change it.
      I think eventually users will primarily use zoom for this and base font-size may go away from browser settings, but until then I'll be using rems :)

    • @coolemur976
      @coolemur976 Pƙed 2 lety +1

      @@TheCoderCoder You should use px just to push internet to the right direction imo. The more devs use px, the sooner all browsers rely on zoom instead of rems. Px is the right way to measure things in web development.

    • @saburex2
      @saburex2 Pƙed 2 lety

      the client asks for rems, you use rems, also they make the page responsive

  • @irffan
    @irffan Pƙed 2 lety +1

    62.5%

  • @geoffreyking1
    @geoffreyking1 Pƙed rokem

    what if em doesn't have a parent font size?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed rokem +1

      If there's no parent, it will be based on the browser settings base font size, default is 16px

  • @briandsouza7854
    @briandsouza7854 Pƙed 2 lety

    Short Answer is Accessibility.

  • @MrWhoever
    @MrWhoever Pƙed rokem

    0:56 I'm using firefox but..
    video closed. :P

  • @AbhishekSharmaOP
    @AbhishekSharmaOP Pƙed 2 lety

    I am so scared of web development.I always forget things and in the end i feel like i learned nothing.What shall i do ?

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +1

      You can always look things up online if you don't remember it right away-- professional web devs always have to do that! And just keep trying one step at a time, and practicing by building even small examples to practice a specific concept

  • @ezra3871
    @ezra3871 Pƙed 2 lety +1

    Happy programmer day everyone!

    • @TheCoderCoder
      @TheCoderCoder  Pƙed 2 lety +3

      Oh wow, I didn't know! Yay 🎉🎉

  • @ziggerwebdesign1704
    @ziggerwebdesign1704 Pƙed rokem

    I haven't used pixels in years

  • @dailymeow3283
    @dailymeow3283 Pƙed 2 lety +1

    rem wins

  • @adammuhtarif
    @adammuhtarif Pƙed rokem

    Salman hersi is a somali guy 😅

  • @mariuszm439
    @mariuszm439 Pƙed 2 lety +1

    worst explanation ever sad!

  • @toscaantosca4541
    @toscaantosca4541 Pƙed 2 lety +1

    Thanks for the video!
    If you don't use sass like me (any reason), you can use this:
    :root {
    --rem: calc(0.0625 * 1rem); // 1px if document font size is 16px
    }
    h1 {
    font-size: calc(32 * var(--rem)); // 32px
    }