Please stop using px for font-size.

  Рет қаралды 195,142

Coder Coder

2 ай бұрын

🔥 Learn how to build a responsive website from a Figma design with HTML, SCSS, JS ➡️ coder-coder.com/responsive/
😎 Join the Coder Coder Club for $5/mth and get sneak peeks of videos: courses.coder-coder.com/p/club
What CSS unit should you use for font size? In this video, I'll show you why you should not use the px unit for font-size, width, and height of elements. The px unit is not affected by the browser's base font size, and so is not accessible for users who want to increase the font-size by using that browser setting. For accessibility, it's better to use rem or em units
0:00 - Intro
0:23 - The problem with px
3:28 - Don't use px for widths
5:32 - Don't use px in media queries
9:03 - Ways to convert from px to rems
12:20 - What about the 62.5% hack?
Resources mentioned in video:
🐙 GitHub repo: github.com/thecodercoder/stop-using-pixels
🖥️ MDN notes on pixels and font-size -- developer.mozilla.org/en-US/docs/Web/CSS/font-size#pixels
↗️ WCAG Resize Text standards -- www.w3.org/WAI/WCAG22/quickref/#resize-text
✒️ Josh Comeau, "The Surprising Truth About Pixels and Accessibility" -- www.joshwcomeau.com/css/surprising-truth-about-pixels-and-accessibility/#the-sixtwofive-trick-13
____________________________
✉️ Want to get emails about new videos, course sales, and other web dev news? Sign up here: coder-coder.com/subscribe/
👕 Get my hoodie here: coder-coder.com/merch
💻 Become a full-stack web dev with Zero to Mastery: academy.zerotomastery.io/a/aff_338z7xnj/external?affcode=441520_ti97uk6b
🎨 Get my VS Code theme: marketplace.visualstudio.com/items?itemName=CoderCoder.codercoder-dark-theme
🔽 FOLLOW CODER CODER
Twitter -- thecodercoder
Instagram -- thecodercoder
#css #javascript #html

Пікірлер: 401
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
It is totally fine to use pixels for things like spacing: margin, padding, gap; as well as border and border-radius. In those cases it actually might be slightly better to use pixels, because having your spacing *not* scale up will leave more real estate on the page for the text, which can help with readability. But I think you can use either px or rems/ems for these cases and they are both fine solutions.
@thestranger8528
@thestranger8528 2 ай бұрын
I'm that UI UX designer you won't want to work with if you don't embrace the beauty of PX. Even my shoe size is 80px
@yannickmichel2566
@yannickmichel2566 2 ай бұрын
I would say just don't mix... like as ur sidebar example... if u do pixels do them everywhere :D
@john_elstar
@john_elstar 2 ай бұрын
Happy 500k subscribers, Coder Coder!
@mina86
@mina86 2 ай бұрын
I’d argue padding and margin should use rems as well since they are often meant to be proportional to text. Someone who needs to set their default font to 32px probably also want spacing between paragraphs to be increased. Also, the way to deal with conversion between pixels and rems is to stop thinking in pixels and use rems. If you’re worried about rounding to full pixels, use one eight granularity for the dimension (i.e. only .0, .125, .25, .375, .5, .625, .75 and .875 fractions; you can use one 16th but it’s harder to remember all the fractions).
@CreateRealWorld
@CreateRealWorld Ай бұрын
Also, feel free to use px for little experiments. :)
@jackdavenport5011
@jackdavenport5011 2 ай бұрын
The main reason I started using em/rem is because it just looks more consistent since all of the font sizes are multiples of the base font size which makes the design of your site look more consistent. I had no idea about the accessibility benefits but I'm glad I do now! Great video :)
@dasten123
@dasten123 2 ай бұрын
For some reason, I have never even thought about using rem on media queries. But it makes total sense!
@peterpancik
@peterpancik 2 ай бұрын
me too, i always use rem when possible but maintain media querries in pixels :D but why frameworks like bootstrap uses pixels ? or newer bootstrap does not ? or bootstrap is a dinosaur ?
@RickGladwin
@RickGladwin 2 ай бұрын
Same here. This really gave me something to think about.
@Action2me
@Action2me 2 ай бұрын
@@peterpancikbootstrap is a dinosaur. It used to be essential, but I haven’t heard of anyone using it these days now that we have flexbox and grid in our toolbox.
@GabrielObioraanderson
@GabrielObioraanderson 2 ай бұрын
​@@peterpancik😂😂😂😂just learn type script instead of bootstrap
@peterpancik
@peterpancik 2 ай бұрын
@@GabrielObioraanderson i think ts is something way different than bs :D but i feel you
@Crowmeir
@Crowmeir 2 ай бұрын
Oh my god, I was searching for how to use Rems and ems a few minutes ago and your video was on the suggested panel! I'm so happy I'm subscribed to this channel!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching! I hope it's helpful for you!
@sanD-xq8nb
@sanD-xq8nb 2 ай бұрын
Hahaha te están monitoreando.
@TheCoderCoder
@TheCoderCoder 3 ай бұрын
🚨 I misspoke at 14:15 - 14:33 -- if you're using the 62.5% hack, I said that "everything on your website will be smaller," but what I meant was the 3rd party packages will be smaller on your website. And you may have to make their sizes LARGER (not smaller) to work on your website.
@najmantube
@najmantube 2 ай бұрын
I've been setting html {font-size: 10px} then body {font-size: 1.6rem} etc for a long time. After watching this, I set the browser font size to 'very large' and the font-size on my web page stayed the same! (as I'd predicted after watching your video). But, following up on an earlier comment on this thread, I went looking for a vscode extension and found one that works: "Convert px to rem" v0.0.10 - by gwanduke. So you could write your entire CSS file in px, then select all/some, then Ctrl+Shift+P, then type: convert px to rem of selections. PS. Excellent video, very informative!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching! That sounds like a great extension too!
@affiliatemonster9136
@affiliatemonster9136 2 ай бұрын
Love the way you explained every case with examples. Great work. Thank you!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
You're welcome, thanks for watching!
@76248
@76248 2 ай бұрын
This is the best argument I have seen for useing rem over px. Great video
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@webdevsingh
@webdevsingh 2 ай бұрын
It's great to see videos on a tip like this! Thank you 😀
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching! Glad it was helpful!
@jordallef2586
@jordallef2586 Ай бұрын
Hello! I'm new to English so I'll try my best to show my gratitude, I must have to get advanced in english and consume much about programming, because here in Brazil the resources are rare. I think I understand what you propose to show in this video, I like the level of English it's easy to know what you are talking about. So starting today I will just use Rem/Em, thanks too much for this video! Peace ✌️
@TheCoderCoder
@TheCoderCoder Ай бұрын
Thanks for watching!!
@zshn
@zshn 2 ай бұрын
I really liked how you explained the merits. Very well done. On the topic of using var vs SCSS functions; I think the issue root vars solve is of distributed values being harder to modify / maintain / update. root variables help centralize the different values used across the system and SCSS functions are not a replacement to it. Even if you use a SCSS function to convert pixels to rem; you now have hundreds of places where magic numbers are used - 16, 32, 24, 1000, etc. As leads / reviewers; I'd like a more consistent model of defining & standardizing those values. So both root vars and SCSS functions can and should be used together. One (root vars) helps in make change configurable and centralized, the other (functions) makes it consistent and reliable.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Great points! I mentioned the CSS custom properties because not everyone likes Sass or may be and to use it at their job. But I agree with you 👍🏼
@john_elstar
@john_elstar 2 ай бұрын
Happy 500k subscribers Coder Coder!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks so much!
@E6hosting
@E6hosting 2 ай бұрын
It took me 10 minutes until I noticed you weren't Kevin Powell, excellent video. Thank you for explaining the maths I always thought rems and ems were just voodoo magic numbers.
@christiaanterveen4633
@christiaanterveen4633 Ай бұрын
I started building a new Drupal theme for the first time in 10 years and came accross rems in the coding standard. Your video really helped me understand how to use them and why this is important. Thank you.
@dandelionwitch
@dandelionwitch 2 ай бұрын
Thank you for considering accessibility in this video! I AM someone who uses the built-in font size setting in my browser for accessibility reasons and always wondered why it didn't always affect things in the way I expect. I see many comments from viewers who don't understand why someone would use the font size setting rather than just zooming. For my own needs, the answer is that the the font size setting's intended behaviour specifically involves increasing the font size across all websites. Zooming w/ ctrl+ or a page's menu increases the size of everything, which is not always what I want. It also functions on a per-website basis unless you use a global zoom setting, which is right next to the increase font size setting in the browser I use anyways. It's not any more work to set a global font size vs a global zoom setting on my end as a user, and font size is more likely than per-page OR global zoom to give me the behaviour I want. If you just need to zoom in to get a better view of one particular thing every so often, per-page zooming works just fine. For someone who needs or prefers ALL fonts to be a certain minimum size across all websites, without significantly impacting the viewing experience of other elements of the page, setting the font size setting in browser is a much better choice. If you read the Josh Comeau article Coder Coder linked, his article explains much the same thing as I've found through my own personal experience.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thank you for sharing your experience! I hope that even though a lot of people are resistant to using rem, that my video can at least help educate those who are willing to change the way they set font-size.
@dandelionwitch
@dandelionwitch 2 ай бұрын
@@TheCoderCoder I really appreciate it! I am new to web development and in addition to my *own* accessibility needs, I think it's fascinating to learn all the ways I could be able to make things that are accessible to as many people as possible! There's so many reasons standard practices shift over time to accommodate different usage needs anyways, imo accessibility is something people should strive to see as simply another creative challenge to learn about
@SkyrimBeast
@SkyrimBeast 13 күн бұрын
Thanks for the video Coder Coder. I'll admit that I've had trouble absorbing the use of em's and rem's. However, I have been using such unit of measurements more and more. I never thought to use em's and rem's in media queries. You've given me something to think about.
@jordankendall86
@jordankendall86 Ай бұрын
I wish when I started learning CSS that they would just start with teaching rem instead of px. It would have saved me a lot of time and brain power.
@quinten01
@quinten01 Сағат бұрын
Agreed. Pixels has become somewhat of a bad habit for me and we all know those are hard to unlearn.
@NishimweRukundoProsper
@NishimweRukundoProsper 2 ай бұрын
Great video! Your tips on responsive design and using rem units really helped me fix scaling issues. Thanks for the clear and practical advice!
@abolajinofiu7956
@abolajinofiu7956 2 ай бұрын
This really explained rem usage clearly and well... Thanks a lot 👍🏿😊
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks so much!
@Kipex
@Kipex 2 ай бұрын
I've gone back and forth with this topic in the past, but I'm sticking to pixels these days. I do appreciate that your video covered the often forgotten media query aspect, which I think is important if you do end up using relative units. I disagree with calling font size based scaling a "modern approach", considering that's basically the original approach from before responsive design and variety of devices was even a concern. Zooming in its current implementation is a more recent addition and answer to user needs. It's more accessible to the user, has a default setting and easy on-the-fly adjustment. Zoom is consistent as everything scales equally. The WCAG criteria "1.4.4 Resize" that you referenced in the video, also supports zooming as a sufficient technique. In fact, if you were to take the rem approach and only apply it to font-sizes, you could easily end up failing that criteria due to clipped text in smaller areas. In this regard I think pixels are far simpler to work with, not to mention the work between designers and coders. I recognize that the font size setting still exists and that a select few may use it, but whichever your approach is, you have provided an accessible way to resize. Chances are many such users are already using the Scale setting in Windows for example as well. They have plenty of good options available :)
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Pixels are easier for web developers to work with, for sure, but we always need to keep the end user in mind. Both zooming and changing the browser font size are tools that are available to users, and so as developers we need to make sure that both those settings work the way users are expecting. Using px will make the browser font size scaling impossible-- so imo as long as it exists in a setting in the browser, I think it should actually function for users. For the clipped text in smaller areas, that is not a failing due to the font-size but would be more of a design problem or using px to set the width of the element that contains the text instead of rems.
@n_mckean
@n_mckean 2 ай бұрын
This is an ironically long response to what is effectively a lazy development approach.
@codex4048
@codex4048 2 ай бұрын
How to out yourself as a person who willingly discriminates? Write a comment like you did here. Although at first glance your reply is a lot better worded than the ableist comment on top, your comment also shows ableism and zero thought about the preferences of the end user.
@n_mckean
@n_mckean Ай бұрын
@@notramiras I’m not sure you understand irony.
@LocherYT
@LocherYT Ай бұрын
This reminds me of an essay a student wrote that was 6pages long about how he did not want to type out alt titles for every image that he used because "his website isnt frequented by those people anyways". People dont know that nobody dictates who should be able to navigate through your web page. Is it a granny with big magnifying glasses, is it someone without arms who uses voice commands, is it a deranged person with an anime profile picture, is it a complete color blind person? Nobody knows and they dont need to know if their approach to web design is universally user-friendly
@cswalker21
@cswalker21 2 ай бұрын
Thank you Coder Coder. CSS is my kryptonite so it's great to see videos with detailed explanations and examples. I'd had this vague understanding that I was supposed to be using ems instead of pixels but it's nice to have all the ins and outs. Outstanding video as usual.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching! I'm glad that this video could help explain px / em / rem for you
@test-rj2vl
@test-rj2vl 4 күн бұрын
That was interesting video. As a backend developer who only knows basics about frontend stuff I have been always wondering why some websites that render correctly on desktop mix way too large font with way too small font. Seems like the answer is that they mix px and rem. If you make more design videos you could even enter smartphone's DPI and font size settings to your dev tools for even more dramatic effect.
@fiskebent
@fiskebent Күн бұрын
Nice video. I feel that the tricks to keep using pixel values will be counter-productive in the long run though. Take the plunge and stop thinking in pixels.
@ichigo6386
@ichigo6386 Ай бұрын
My mother knows how to zoom in but prefers a larger font size. Some people said users can just zoom in but I find it a bit annoying when having to swipe left and right continuously just to read text on a website. That's why browsers support changing font size.
@TheCoderCoder
@TheCoderCoder Ай бұрын
Totally agree
@wamique
@wamique Ай бұрын
So the main thing isn't just not using Pixels, the main thing is not to set default font size for the website? So that the fonts can be changed from the browser
@gennagraphics
@gennagraphics 2 ай бұрын
Its good to see you back. So. rem usage is the best
@jrom_ai
@jrom_ai 2 ай бұрын
Love this content 😍 Well done!
@Adnan_Inspires_Official
@Adnan_Inspires_Official 2 ай бұрын
NIce!!! Thankyou!! You are the first Female coder on KZbin that I saw. I just Subcribed as well one again thankyou!!
@kj_sh604
@kj_sh604 2 ай бұрын
dang… looks like I'm rewriting my personal websites, this weekend 😆. Great vid!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
haha! Thanks for watching!
@j-lewis
@j-lewis Ай бұрын
Girl, you're the eyes-opener, you know that? I'll subscribe, good stuff!
@MrSuprashadow
@MrSuprashadow Ай бұрын
Very cool CSS variable idea! It's easy for me to use rem now.
@VJK102
@VJK102 6 күн бұрын
This is a nice video; Don't think I'm gonna use it at my job any soon, tough We work with a mobile app, so vh/vw and hard on px gonna still be my main units
@hcmac100
@hcmac100 2 ай бұрын
Thanks so much for your time and knowledge - total respect !
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks so much!
@dr3amerz3ro
@dr3amerz3ro 2 ай бұрын
amazing video, you are one of the gratest teachers i ever seen i suscribe rigth now.
@mverma7845
@mverma7845 2 ай бұрын
Thank you CoderCoder, really great video.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@mverma7845
@mverma7845 2 ай бұрын
@@TheCoderCoder whats the difference between em and rem, I don't see much difference between them?
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
​@@mverma7845rems are only dependent on the root font size, but em's are dependent on the parent and any ancestor element. So if you have multiple nested elements that have em's, you will have a compounding effect which can make the element's size much larger or smaller than you would expect. Rems were created specifically to not have the same quirk. Hope this helps!
@mverma7845
@mverma7845 2 ай бұрын
@@TheCoderCoder in the root if use font-size: 1rem; then through out my code I use font-size: 2rem etc, it will go off of the root font-size correct.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
@@mverma7845 I'm not sure if this is what you're doing, but you don't need to set the root's font-size in your CSS (like html { font-size: 1rem; } ) -- it will automatically take it from the browser settings. But yes, setting a font-size of any element to be 2rem will be 2 * the browser font size.
@montyksycki4092
@montyksycki4092 21 күн бұрын
Thank You for SHARING!!! 🙏🏼🙏🏼🙏🏼🙏🏼🙏🏼 🙂
@ianschneider970
@ianschneider970 2 күн бұрын
Hello. New to the channel, thanks for this informative and educating video. May I ask what kind of keyboard you're using? (that's broken to 3 parts).
@TheCoderCoder
@TheCoderCoder 2 күн бұрын
Thanks for watching! The left and right parts are the Glove80, and the middle numpad is a separate board I got off of amazon
@lowlay964
@lowlay964 Ай бұрын
Thank you! This is really informative!
@lann1sterroy
@lann1sterroy 8 күн бұрын
thank you so much for great content Jess, I truly appreciate your work. Could you please explain why you use em instead of rem in media queries, sorry if i missed that part. Thanks.
@TheCoderCoder
@TheCoderCoder 8 күн бұрын
Em and Rem are pretty much identical when using media queries-- I just use em's out of habit. There used to be a bug in Safari when using rems in mq's, but that's been fixed now, so either is good!
@lann1sterroy
@lann1sterroy 8 күн бұрын
@@TheCoderCoder got it, thank you so much for clarification and your time.
@DrDurango
@DrDurango 11 күн бұрын
What is wrong with increasing zoom?
@stevejohns3410
@stevejohns3410 2 ай бұрын
I like your explanation. New subscriber here.
@skiesaboveunlimitedstargaz7316
@skiesaboveunlimitedstargaz7316 2 ай бұрын
I agree. Back in 2015 I would use px.. But now, I am using "rem for Font Sizes" since we are relying in mobile responsive in many different devices... I don't need to explain here, you can do some research and investigation. Everything she says, it is true. 👍
@stevejohns3410
@stevejohns3410 2 ай бұрын
Thanks. I am working on my website and this is most helpful. Now I am looking for video for backend that explain how newsletter subscription function.
@johnmaleek6879
@johnmaleek6879 2 ай бұрын
Thanks a lot for this information. Great content 👏
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@devkasunlakshitha
@devkasunlakshitha 2 ай бұрын
Really helpful video. I like that scss solution to use REM. Still love scss same as you
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
SCSS is awesome. Thanks for watching!
@AdeyCoder
@AdeyCoder 2 ай бұрын
I like the content learned new. thank you & keep it up.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@itsthemangler
@itsthemangler 4 күн бұрын
I remember when I was an intermediate level coder and I agreed with this. Don't worry, you'll grow out of it when you learn more.
@aldo6532
@aldo6532 2 ай бұрын
Very good video, this. I cannot help but wonder though how many people actually change the base font size (or even know it can be changed) vs changing the base Zoom level instead (which is always one of the easiest settings to find usually right in the toolbar)
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Zooming is used more, I'm sure, but there are still users who use the browser font size. Personally, I think that as long as the setting is in the browser we need to allow it to have an effect on the website.
@gabrielrochasantana
@gabrielrochasantana 23 күн бұрын
Great explanation,thanks.
@Novacification
@Novacification 14 күн бұрын
The only real use case I can think of for using REM, is to scale everything responsively by lowering the base font-size in your media queries on lower resolutions. Padding, margins, text and everything else will take up less space. You can clamp your actual text size tokens/CSS variables to avoid them going below 14px - and of course other minimums for e.g. medium and large sizes, so you don't go below accessibility requirements where you might have low contrast.
@Fede_uyz
@Fede_uyz 21 күн бұрын
Also on mobile most phones have a designated base font size, and many people increase it for accessibility, comfort or personal preference. Ive seen 20smth year olds have it super small to fit more text, or bigger than normal to aid in study effectiveness
@msegmx
@msegmx 11 күн бұрын
The "rem" function is a great idea. One improvement though, instead of concatenating with "rem", better multiply by 1 rem, so that the result is treated as a unit "rem" rather than a string "rem". Instead of "math.div($pixel, 16) + rem;" use "math.div($pixel, 16) * 1rem;". That way, you can reuse the function in other Scss calculations.
@TheCoderCoder
@TheCoderCoder 11 күн бұрын
that's a great suggestion, thank you!
@kenanbrunner9199
@kenanbrunner9199 2 ай бұрын
Great Video! Still I have a question left: Would you not use pixel on media queries if you create a image layout? Since i wouldn't want the images to break into multi-column layout earlier/later than intended if the user changed the base font-size.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks! It's hard to say, but I'd check how it looks when you change the browser font size, and if you like how it looks and you and see all the images fine, you can choose what unit you wanna use for that
@nomadshiba
@nomadshiba Ай бұрын
also changing font-family effects font-size too, so using em/rem will be more consistent when you change font-family as well
@tiaanbasson9092
@tiaanbasson9092 2 ай бұрын
I'm a C/C++ dev that does some web dev for some projects. I've noticed A lot of third party frontend frameworks using pixels for font. Personally I feel the way web rendering has been implemented is poor insufficient design. Take game engines for example, font rendering is either done through vectors or font sprite sheets, the latter uses less resources but comes at the cost of quality when upscaled, usually the sizes are changed by having a base integer size which gets scaled based on the screen resolution. This can all be handled automatically behind the scenes by using a list of standard display resolutions like game engines do. A function can be added to override sizes by the developer if needed.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Wow, that's really interesting about how game engines handle scaling text. The vector approach definitely sounds more efficient than what's on the web
@陈大锤-q1s
@陈大锤-q1s Ай бұрын
Good video, great help!
@souvikmukherjee2349
@souvikmukherjee2349 2 ай бұрын
Thank you so much ma'am, got to learn a lot
@joseflinha
@joseflinha 2 ай бұрын
1. Heading size in REM. Does having a full-screen title really improve accessibility? The size of the title itself is sufficient, there is no need to increase it further. So using REM matters. 2. Use REM to determine width. It makes sense in the demo, but if you're designing a page where you want 300 pixels, you really want 300 pixels there. The content part on the left may not fit what normally fits. So using REM matters. 3. Using EM in media queries also matters. If the desktop design is supposed to be two columns, why should it be affected by the font size? It works in some cases, but really everywhere? This way I might see the tablet version on my desktop with enlarged font. So use REM and EM, but wisely.
@zearthus7089
@zearthus7089 2 ай бұрын
I do not agree not totally use pixel, there are specific layout by the designers which can only be controlled using pixel from different devices width. I totally agree if your website layout has a basic design which not affected on increase font size and div width, but for some website which has layout incorporated with design pixel size still require
@LazyTechDaily
@LazyTechDaily 2 ай бұрын
You're right . Text in some elements should not scale that's why px is still needed . Everything has its own use.
@galkovskiy
@galkovskiy 2 ай бұрын
Okay, looking at the examples in the video, I get the feeling that it's better not to use pixels at all. Is this correct, or are there still situations when it is better to use pixels?
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
I didn't include this in the video, but pixels are fine to use for smaller things like margin, gap, padding, and borders and border radius.
@emerelle3535
@emerelle3535 2 ай бұрын
rem - rapid eye movement - the movements of your eyes when you try to captures the letters all over the screen. :) Feels a litte bit like imperial units (or what I think imperial units would feel If I had to convert them in my head) but it makes sense and I had no idea it existed. (rem, not imperial units xD)
@pitogrillo
@pitogrillo 2 ай бұрын
This also applies to e-books. Some of them are designed in pixels and when opened on an e-reader everything looks a bit disproportionate.
@Pareshbpatel
@Pareshbpatel 2 ай бұрын
Great tutorial on why we sould not use pixels for font-size and size. Thanks. {2024-08-06} - Subscribed!
@Bond-zj2ku
@Bond-zj2ku 18 күн бұрын
Could you please make a website coding tutorial for this topic only as new commers still might not get it completely.
@jeffmccloud905
@jeffmccloud905 2 ай бұрын
One case where you might not what to do this is with border-width. Or maybe with box-shadow sizes and blur values.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Totally agree!
@ramzyabdul185
@ramzyabdul185 2 ай бұрын
So for text should we use rem's or em's. I always don't know the difference between the two. Or its fine to use both. Because I am a beginner and want to get the best practice
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
You can use either, but I usually use rems. Em's have a quirk where if you have nested elements that are using em's they have this multiplier effect that can make the text have an unexpected size
@ramzyabdul185
@ramzyabdul185 2 ай бұрын
@@TheCoderCoder ok now I c. Thanks for taking your time to respond to me 🤗🤗 I really appreciate it and I will definitely take this to consideration
@supereasy131
@supereasy131 2 ай бұрын
Most browsers allow you to zoom even when you have fixed px sizes. If you set fonts to values ​​like rem, that means you have to size all padding and margins and other elements in rem, and you have to make sure that your design doesn't break at all zoom percentages. 50%,51%,52.... Of course, you can do it, but your design will be very monotonous.
@n_mckean
@n_mckean 2 ай бұрын
The fact that you said “Most browsers” proves the point of using rem. And sure, you can choose or not to choose rem or em for spacing too, it’s not difficult. There are plenty of values in CSS to help control it, min, max, clamp etc.
@TheMetalMag
@TheMetalMag Күн бұрын
thx for the explanation
@letmewatch.
@letmewatch. 2 ай бұрын
I always knew I should be using rems and ems for (for responsiveness, but I didn't know what I was making responsive, I initially thought the font just scales down on smaller devices) sizing but always sticked to using pixels since its just a lot easier working with them (as a junior developer focused on making things look good on 3 breakpoints and standard base font size). I didn't know I needed this video, it was very useful, I finally understood the concept behind ems and rems. What do you think is the difference between ems and rems though? Why do we typically use rems for all things fonts and ems for all thing elements? Would really appreciate your response to this
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
I personally use rems for everything, because em's have this quirk where there's a multiplier effect if you're nesting multiple elements that all use em units. I do think one useful application for em is to use it when you're setting margin-bottom of text elements, bc it will be dependent on the -size of the element itself and so will scale with the font-size which I think is nice! Thanks for watching!
@letmewatch.
@letmewatch. 2 ай бұрын
@@TheCoderCoder stellar! I can't thank you enough for replying!
@PabloSanDev
@PabloSanDev 2 ай бұрын
Great video thank you for sharing your great knowledge
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@SurenEnfiajyan
@SurenEnfiajyan 2 ай бұрын
The downside is that ems / rems will multiply even the already huge number of device resolution combinations by font size combinations, which means a lot more testing. A headache for developers and designers. In the vast majority of cases zoom is good enough since all the sizes are scaled consistently.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
@@SurenEnfiajyan I'm not sure what you mean by "font size combinations." And while zoom does work, some users use the browser font size setting, and pixels are not compatible with that. Using rems or ems is simply the more modern and accessible approach to font-size.
@SurenEnfiajyan
@SurenEnfiajyan 2 ай бұрын
@@TheCoderCoder By "font size combinations" I mean the number of possible font sizes provided in the browser settings. Say, Chrome provides 5 different font sizes in the settings, this means you might need to test for all the device resolutions for every chosen font size, this mean five times more possible combinations. From my knowledge the vast majority of users (including visually impaired) aren't even aware of the font size setting and don't even know where it is, they usually use zoom. Also oftentimes using em / rem causes ugly numbers, something like 1.375rem, which is less readable and slightly increases the CSS code size. Theoretically rem/em might look better than zoomed site, but the vast majority of developers still use pixels because the designs are also done in pixels and the website is not tested for different font size settings. So considering more costs / testing, less control for developers / designers, relatively low usage of font size setting and somewhat less readable code, there is usually not much incentive to use em / rem.
@JustinDomanais
@JustinDomanais 2 ай бұрын
Thanks! that's awesome features using CSS!
@digitaldevigner4080
@digitaldevigner4080 2 ай бұрын
I still feel like designs should stop using tiny fonts and then this would not really be a thing anymore. This came about because some designers insist on using very tiny fonts to cram more into a smaller space. I have worked on mobile apps where the UX designer insisted on using 11pt fonts to fit more. The designs were so dependent on fitting things into a small space like an e-commerce product list page that we had to purposely block the ability for the font size to increase. Not saying that was the right thing to do. Just that I really think this depends and isn’t an end all rule. Px still exists as an option for a reason and telling designers/developers to not use it anymore feels odd to me. Of course the designs should adapt as much as possible and every effort should be made to support this. That’s not always possible however and sometimes we have to pick our battles with UX and business partners. If designs didn’t insist on using such tiny fonts to begin with this may not even be much of a concern anymore. The reality is if a design feels it needs 11pt fonts to work then allowing the user to blow that up to 24pt or 32pt font size is likely going to do a lot of damage. If the design works well with adaptable font sizes then it probably shouldn’t be using 11pt fonts in the first place because it’s unnecessary. This all depends on the primary of the project. Is it purely content based or more design structured. A blog, wiki or news site absolutely support this. E-commerce, well that may be a bit more challenging and this might become more of a well it depends.
@nbot3000
@nbot3000 2 ай бұрын
what if the browsers have a zoom feature? you can just hold ctrl + scroll mouse wheel to preferred scale?
@0xBerto
@0xBerto 15 сағат бұрын
Wow. Thank you
@alvaroprietovideos
@alvaroprietovideos 2 ай бұрын
this video was good, thanks for sharing
@maxk6655
@maxk6655 Ай бұрын
I don't know single person who changed font size in browser. And I think all browser has option to set minimum font size and this will apply also for pixels. But I know if people can't see something they use zoom option that will works for PX too. So if you want use PX, use it. But if you really have to use rem/em but want to use pixels there's plugin for postcss that will convert PX to rem when compiled.
@chrisicotec7652
@chrisicotec7652 2 ай бұрын
i cant remember the last time i used pixels for anything other than as a 0px minimum size or a 1px border or outline... i do everything like margins padding or gap with em or rem, ocassionally for vertical padding i will use vh instead.... with fonts its always em or rem, sometimes i will use % of the parent element.... when im defining a universal base size for different repeating text tags i always use a font size with a min size clamp so i dont need to redo anything with media queries for them.... yeah the 62.5% trick does have compatability issues when it comes to third party packages, simple solution there is i dont use any third party packages, theres nothing that bootstrap, tailwind or any other package can do that I cant if i take the time to sit down and do it
@rayanuki
@rayanuki Ай бұрын
Unfortunately, we mostly create websites to satisfy clients who literally don't care about accessibility. As long as it looks good on an iPhone and Mac, all's good. If text looks bigger cause of accessibility, it's bad.
@yannickmichel2566
@yannickmichel2566 2 ай бұрын
but honestly nobody will increase font size via browser settings since I think not much people know about it and also cmd+ is now much more used especially since on mobile devices "browser settings font size increase" doesn't exist. they rather use the -/+ to inverse font sizes which actually will increase px font size! but anyway I think rem is the new way to do it like webp is the new way for images on the web so I think everyone should adapt to what's new since we all had to when apple introduced retina displays to the world and we devs had to scramble on how to do images for such high density pixel displays and now we even got to @3x hahaha thanks anyways! keep up the good work by dear coder coder
@yenthompson9471
@yenthompson9471 2 ай бұрын
We do. Most people won’t know it because most people do t have visionnimpairment. Most of us who need it know a setting like this exists.
@niteshbabu5731
@niteshbabu5731 2 ай бұрын
62.5% will also cause issues when the users change browser font sizes. For example, if they change it to 32px, they'll still see 20px but not 32px which will be really frustrating, not to mention accessibility issues.
@EugeneLeslieAcquaye
@EugeneLeslieAcquaye 6 күн бұрын
Is it okay and right to blend px and rems in your work? Or that is going to cause a lot of issues.
@TheCoderCoder
@TheCoderCoder 6 күн бұрын
It should be fine to use different units in 1 website, because ultimately they all become pixel sizes in the browser. It shouldn't cause issues unless you're doing something very extreme
@DaveCollison
@DaveCollison 2 ай бұрын
Personally, I don’t think in pixels at all. It’s better to just think in rem. No conversion necessary. With the size of screens and their pixel density these days, why not just work in rems?
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
I'm a huge fan of this and have started to do this when I'm working on solo stuff! Unfortunately, for people working with a designer who's created in pixels, it may still be necessary to convert
@DaveCollison
@DaveCollison 2 ай бұрын
@@TheCoderCoder Yeah, I always forget that people collaborate. I do everything on my own so I have the freedom to work however I want. It's very freeing.
@paulroos8517
@paulroos8517 2 ай бұрын
Excellent video!
@paulambrose5442
@paulambrose5442 2 ай бұрын
Cool stuff. Might build a vsCode extension that automatically converts to rem onsave
@najmantube
@najmantube 2 ай бұрын
This one works pretty well (select line, block all then convert): Convert px to rem. v0.0.10. gwanduke
@DjCtavia
@DjCtavia 2 ай бұрын
I don't do front-end that much, but everytime I went on videos about EM / REM, I had the same issue. It was half clear, but with this video every little spot missing elsewhere disappeared. This is high quality content, examples clear and well worked. Probably how you are everyday, but love the pace you have for speaking!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Really glad that this video helped! Thanks so much for watching
@Dron008
@Dron008 2 ай бұрын
Well, it is very arguable. Nowadays few people use this approach with changing font size in settings. It is easier to zoom in. Unfortunately in mobile Chrome it doesn't work good but it desktop it is ok. REM has disadvantages too. If we have a card with image of 20px and one line of text we want to be sure they are of the same height. Pixels in CSS are not physical pixels so you shouldn't worry about screen size. We use pixels in our site and don't have any problems.
@n_mckean
@n_mckean 2 ай бұрын
CSS has controls to set a uniform height of cards, despite their content. The rest of your response just has me shaking my head. The first step in accessibility is empathy.
@SerenModz21
@SerenModz21 2 ай бұрын
what are pixels? i forgot what they are because ive gotten lost in the land of tailwind. jokes aside, great video! ever since i started using tailwind, i just think about tailwinds sizing instead.
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
haha! Thank you for watching!
@Ethiofunnyshorts
@Ethiofunnyshorts Ай бұрын
I usually set borders and some properties in pixels coz i don't want them to be thicker and thinner based on the root settings
@dominikdominik1139
@dominikdominik1139 Күн бұрын
People with low it skills are not able to change font size of the site, but they are able to zoom the site on 110% for instance. So using pixels while developing is still okay.
@RS-fy9hb
@RS-fy9hb 4 күн бұрын
For the converting px sizes into rem/em, wouldn't it be a pretty good solution to make an auto correct / script in whichever IDE you use, with some kind of syntax, then be able to calc pixel size into rem and then replace the written syntax with the result? I feel like that wouldn't be that difficult, like a double ..then 10px > turns into > 0.625 ?
@RS-fy9hb
@RS-fy9hb 4 күн бұрын
Lmao, I guess I should've read the comments, turns out there's an extension xD.
@sivanyamurayama5523
@sivanyamurayama5523 2 ай бұрын
Lesson Learnt, I will now start practicing with rem instead of px, thank you for the info 👍
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Awesome, glad it could help!
@ashique12009
@ashique12009 2 ай бұрын
Okay, so we should use rem instead of px but client gives px in psd or figma to match markup then what should we do? Should we convert every px to rem first like 16px is equal to 1 rem then apply the rem on markup? So if in figma we get h1 in 16px then in markup we should use 1rem as font size in that h1?
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Yep, that's exactly right!
@MaxWeir
@MaxWeir 2 ай бұрын
What if your side bar needs to be 300 pixels on tablet and desktop? My client runs ads in the side bar so I need to keep the width fixed for tablet and desktop
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
I haven't worked with ads but I could definitely see using pixels for cases like that where you don't want it to scale up, esp for image or video ads that are exactly at 300px
@WithDebugger
@WithDebugger 2 ай бұрын
Don't try to be compatible with all devices with one code. Please design a layout specifically for devices with small screens.
@speedhunter7303
@speedhunter7303 9 күн бұрын
Depends from person using it..but dont say 'stop' using..some people use rem just to look fancy..Pixel is there for a reason..
@dzigayu4944
@dzigayu4944 17 күн бұрын
Using rem just makes my styles look so much consistent and coherent.
@The-Athenian
@The-Athenian 2 ай бұрын
Not that I don't believe you, but I've never seen anyone change the browser font size. Not in 20 years of using computers have I ever even heard about it. It does seem somewhat useful for responsiveness though. Making most sizes a multiplier of the default font size doesn't sound like a bad idea. I'll have to experiment.
@hitesh3859
@hitesh3859 16 күн бұрын
@codercoder your function to convert pixels to rems always Divides by 16 which is hard-coded , but the browser pixel size can be different , can you clear out this confusion ??
@TheCoderCoder
@TheCoderCoder 16 күн бұрын
It assumes the default value of 16px = 1rem, which is what the design is based off of. But since the final value in the CSS is rems, it will allow the user to increase the font-size by changing their browser font size. As long as the user has control over the sizing then it will work the way it is intended. Hope this helps!
@birgitleitner1453
@birgitleitner1453 2 ай бұрын
As a user I‘d zoom in, as a front-end developer I appreciate this input and will try it. It’s awesome I finally found a female content creator in Front-end yey!
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
Thanks for watching!
@codetheworld6721
@codetheworld6721 2 ай бұрын
Your awesome, thankyou for the very helpful tip
@TheCoderCoder
@TheCoderCoder 2 ай бұрын
You're very welcome!
World‘s Strongest Man VS Apple
01:00
Browney
Рет қаралды 59 МЛН
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 31 МЛН
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
World‘s Strongest Man VS Apple
01:00
Browney
Рет қаралды 59 МЛН