This flowchart will help you pick the right CSS unit

  Рет қаралды 53,349

Kevin Powell

Kevin Powell

Күн бұрын

Пікірлер: 110
@dillxn554
@dillxn554 Жыл бұрын
This is like a meme someone would make to poke fun at CSS 😂 Good work, Kev
@yurihuffles
@yurihuffles Жыл бұрын
I loved that you started this video with "there are exceptions", and then go on to the first go into an area where I'm frequently working in those exceptions. I code a lot of streaming overlays live, and my starting point is that I set a root font size, in pixels, calculated in css based on formula using viewport heights. I do this since I design on a 1080, so this sets the root font size to be what I view as the smallest viewable when viewed full screen on an old phone, but in a way that it'll scale up if someone streams in 4k, etc. It also means the rest of my font sizes can be in rem with me knowing that's going to look the way I intend. I've had people often cite you, and state I'm wrong - so from here on out.. I'm going to just add a command that links to this video with "watch this... I'm in the exceptions!" :)
@KevinPowell
@KevinPowell Жыл бұрын
Haha, definitely! I've made a couple for myself and that's definitely the way to do it :D
@HenriqueErzinger
@HenriqueErzinger 4 ай бұрын
That’s not an exception really. The root font-size is a special case, since it exists to control the calculation for all the rest. It is a pixel value no matter what.
@SunilSuresh786
@SunilSuresh786 Жыл бұрын
Thanks for this really helpful flowchart! When designing pages, my biggest problem is what unit to use. Usually, I use px by default, or rem/em to make things responsive, but this doesn't always work. But now, not only do I have a better idea of what unit to use (thanks to your flowchart), but your tips also help make it clear why something does not work (like, when using % to specify an element's height relative to another item, I now know that the other item's height also needs to be declared). Thanks again. 🙏
@kh_trendy
@kh_trendy Жыл бұрын
I love how you immediately pointed out "there are exceptions!", Kevin! This is why CSS is hard though, experience tends to give you the knowledge to identify those exceptions!
@fersahahmet9597
@fersahahmet9597 Жыл бұрын
This is what i call content generating, great job as always.
@KOBE42__
@KOBE42__ Жыл бұрын
This is the best way to navigate all the different units for sure! Thank you for taking the time to create and share this. Very useful ❤
@Trademm
@Trademm Жыл бұрын
This is some original work, appreciated
@marksto6581
@marksto6581 Жыл бұрын
This is so great to have such a thought-out thing right at hand now, when you're queried with that same old question once again (and then again, and again, ...). Thank you so mush, Kevin! Two thimbs up!
@twd2
@twd2 Жыл бұрын
That's exactly what I needed, great video as usual😍!!!
@joan_ferre
@joan_ferre Жыл бұрын
You're AMAZING Kevin, thank you so much! Love your explanations. Learned something new with the `ch` size!!
@MrBrady95
@MrBrady95 Жыл бұрын
Wow, this flowchart is amazing! Thanks!
@kirkanos771
@kirkanos771 Жыл бұрын
This is gold. Thank you Kevin.
@jinbyun
@jinbyun Жыл бұрын
I should make a cli tool out of this. This is gold!
@TheRalic
@TheRalic Жыл бұрын
Awesome job, thank you for taking the time and making this!
@jikochi
@jikochi Жыл бұрын
nice chart! great job, thank you Kevin. maybe the finalized version of this can be in the form of a form. we can see what we will use on the result screen. just an idea. But it's always nice to see the wider perspective. it's also can stay that way. 😄
@lowwastehighmelanin
@lowwastehighmelanin Жыл бұрын
This is incredibly useful, thank you Kevin!
@luketurner314
@luketurner314 Жыл бұрын
17:43 I believe "couldtry" should be "could try", just a missing space typo I noticed
@jessypouliot8374
@jessypouliot8374 Жыл бұрын
From my use cases, most of "position" cases are `0`, `50%` or `100%`, I never use px and sometimes use rem
@tomvoltz7506
@tomvoltz7506 Жыл бұрын
Great chart! Thanks Kevin.
@Kozi03
@Kozi03 Жыл бұрын
You are a CSS angel
@i_am_ergo
@i_am_ergo Жыл бұрын
You're the real MVP, Kevin. 🏆
@skrundz
@skrundz Жыл бұрын
How is it possible for CSS to have even worse units than the US 😄
@Objectified
@Objectified Жыл бұрын
The U.S. also uses the metric system, genius.
@HenriqueErzinger
@HenriqueErzinger 4 ай бұрын
It doesn’t, at all.
@iliyanpetrov5762
@iliyanpetrov5762 Жыл бұрын
Kevin owned any AI Thank you, Kevin, you are awesome!
@nilaallj
@nilaallj Жыл бұрын
Correct me if I'm wrong, but I'm pretty certain that even font relative units does not respect the user's typography settings when used in a root font-size declaration. That will always make 1rem equal to 16px no matter what. The only way to have the user's settings trickle down the cascade, while still adjusting the root font size, is by using percentage units. So instead of declaring 1.2rem it's better to declare 120%. That could also be used in clamps together with viewport units etc. (Again, this should only be used when adjusting font size on the root element. Percentage units on font sizes is a bad idea elsewhere).
@KevinPowell
@KevinPowell Жыл бұрын
root font size is not always 16, no. If the user sets their browser font-size to 21px, 1rem = 21px. If they zoom-in/out it also changes the root font size. using % is dangerous for font-size in the same way em is (they're almost the same, really), in that if you declare a font-size on an element, and then a child of that element, they are multiplied on top of each other, and not based on the root font size all the time.
@nilaallj
@nilaallj Жыл бұрын
@@KevinPowell What I meant is that using em on the root font size overrides the user’s browser settings. If root font size is set to 1.2em it will compute to 1.2 * 16px, not 1.2 * whatever font size is set in the browser. If you want the browser settings to trickle down in the cascade you should use % on the root. Not declaring a font size on the root will make 1rem be equal to whatever is set in the browser.
@audiocologne
@audiocologne Жыл бұрын
WOW, great! This is very helpful, thank you very much 🙏
@crousdioll
@crousdioll Жыл бұрын
This help is very important thank you
@AmandaLenoard
@AmandaLenoard Жыл бұрын
Thank you so much for this!
@peterloader974
@peterloader974 Жыл бұрын
Fantastic! But I want a pdf of the chart so I can print it and hang it on the wall! How much?
@XCanG
@XCanG Жыл бұрын
I thought it would be more extensive, also I don't like an idea of omitting possible variants because it exactly the reason you may want to look at this chart. For example even same grid often require you to use minmax() function. Also there is a thing to sizes and spacing in a document and in an element. For example you did say at the beginning that you probably don't want to use % on position, but there is a lot cases where you just have to use something like: .el::before { left: 50%; translate: -50%; } (same could be for height), but the point is that there left centering element top left corner within a parent element (with position: relative;, otherwise within document) but translate position 50% back to center of element, since it take size of an element, in this case size of pseudo ::before
@justindouglas3659
@justindouglas3659 Жыл бұрын
Could you also do this for other properties like when to use psuedo classes and stuff like that.
@philippfischer
@philippfischer Жыл бұрын
Great job, thank you Kevin!
@palrevesz8629
@palrevesz8629 Жыл бұрын
Thank you Kevin, that's gonna be so helpful... 👍🌞❤
@jasper265
@jasper265 Жыл бұрын
I mostly use percentages for font sizes. From your explanation, they're equivalent to em in that context, but I'd say it's more self-explanatory. Do you have a reason you're picking em instead of percentages there?
@selectorsaurus
@selectorsaurus Жыл бұрын
Hey Kevin! Awesome chart! Lately, I've been thinking about ditching rem units "everywhere" and leaning towards using px for things like paddings, gaps, and margins between certain block elements/components. The reason behind this pondering is that when you change the browser's font size, the layout grows, and the text becomes practically unreadable as its space shrinks. So, considering using rem for font size and px for most of the layout. Does that sound reasonable, or do you have any thoughts on such an approach? Thanks again!
@GrantGryczan
@GrantGryczan Жыл бұрын
ems and rems are specifically intended to scale with font size, so you should only use ems and rems when you specifically want things to scale with font size. Mobile devices, for example, tend to have a much larger em-to-px ratio than desktop, so if you want something to be larger on mobile than desktop (for accessibility), then you might consider ems or rems. These are things you should always be mindful of when picking these units.
@HenriqueErzinger
@HenriqueErzinger 4 ай бұрын
Right off the bat, percentages are the better option for positioning half (or more) of the time, and rem almost never. Using percentages allows you to not care about the actual size of the container, and using rem ties your object’s position to the font-size, which in general makes no sense at all. I also don’t like to use em. I do understand the appeal, but I prefer to be more precise with my spacings, following a proper baseline grid, than letting the browser calculate some magic number (which is not actually what it does, but feels the same). There are definitely some cases where it’s nice to change based on context, but most of the time I’d rather keep tight control.
@zadina308
@zadina308 Жыл бұрын
Really useful … thx a lot Kevin!
@nomad100hd
@nomad100hd Жыл бұрын
Gross I clicked to open the chart in Figma and audio started playing. Thank you for the useful flowchart and the video is great.
@db5443-j8l
@db5443-j8l Жыл бұрын
Great content as usual. Took all your classes. Question, where can i find best practices/guidelines by MDN or something?
@kaywelfare3500
@kaywelfare3500 Жыл бұрын
Christ, you're such a legend!🙏
@blizzy78
@blizzy78 Жыл бұрын
awesome, that's very handy, great stuff
@paszTube
@paszTube Жыл бұрын
Would love to have a printable version of this... Or how about an A3 or A2 poster in your shop?
@SenselessUsername
@SenselessUsername Жыл бұрын
I tried to make a CSS version to put as a reference on a personal webpage, but couldn't figure out what units to use.
@paszTube
@paszTube Жыл бұрын
@@SenselessUsername hehehe
@cool_scatter
@cool_scatter Жыл бұрын
In the block where you mention that em is relative to the parent's font size, you say .5rem instead of .5em.
@KevinPowell
@KevinPowell Жыл бұрын
oops! Sorry, hopefully it's clear what I meant :)
@cool_scatter
@cool_scatter Жыл бұрын
@@KevinPowell From the video, for sure. Just looking at the flowchart it would be tougher if you didn't already know how it worked.
@nobir98
@nobir98 Жыл бұрын
At long last you've posted that
@richochet
@richochet Жыл бұрын
Thanks Kevin! I am though having trouble seeing this in Firefox / Windows 11
@GerritforBazeja
@GerritforBazeja Жыл бұрын
I like this flowchart.....Thank's
@ViewMumbai
@ViewMumbai Жыл бұрын
You’re awesome ❤❤
@najmantube
@najmantube Жыл бұрын
Is there a problem with setting font-size: 10px on the html, then using rems after, eg. body {font-size: 1.6rem } (1 rem = 10px, 1.6 rem = 16px) etc?
@RobertSaulnier
@RobertSaulnier Жыл бұрын
A printable version would be great
@KevinPowell
@KevinPowell Жыл бұрын
I think it's way to big, lol. Maybe I'll make a simpler version for print, but it might be a bit before I get around to it.
@LePhenixGD
@LePhenixGD Жыл бұрын
Hi Kevin !!! I have a slightly off-topic question for you, if I'm not mistaken I recall watching a video that demonstrated a HTML-CSS only technique for adding a subtle effect to heavy images using a background-image with a compressed version of the original. This approach created a captivating transition where the high-quality image "took over" I'm trying to confirm if this was one of your tutorials, specifically the video mentioned the need to add a special HTML tag for images. Did you happen to make that video ? If yes, could you please provide me the link to it ?
@KevinPowell
@KevinPowell Жыл бұрын
Yup! Here you go: kzbin.info/www/bejne/aWWYh2WDiph4ldk
@LePhenixGD
@LePhenixGD Жыл бұрын
Thanks!
@NiceChange
@NiceChange Жыл бұрын
Great video. Thanks for the info!!! Demystify
@stratman1234
@stratman1234 Жыл бұрын
Very helpful. Thanks a lot.
@n8_may
@n8_may Жыл бұрын
Does Kevin have a video explaining why max-width and min-width are problematic?
@KevinPowell
@KevinPowell Жыл бұрын
max-width is fine, it's min-width that can cause issues. It's not that it's bad all the time, but it's a quick way to run into overflow issues. Same with max-height :)
@ahammedshajmeer
@ahammedshajmeer Жыл бұрын
some video links aren't redirecting
@trudyandgeorge
@trudyandgeorge Жыл бұрын
Damn. Host site is down :(
@rajraiz3058
@rajraiz3058 Жыл бұрын
What Mindmapping tool do you use by the way?
@AlThePal78
@AlThePal78 Жыл бұрын
em n rem still confused me when to use it. like i would like to see where in a real world scenerio in a actual site. This video makes some sense but I just never use em
@sefnerr
@sefnerr Жыл бұрын
un-CSS related; What program is Kevin using to make that flow-chart? TIA
@Skorupa9
@Skorupa9 Жыл бұрын
Wow. It's so helpfull!
@JosephCodette
@JosephCodette Жыл бұрын
EM relative to it's parent so if the parent is 3rem and child is 0.5em the child becomes 1.5rem , ?!? huh somehow missed that logic apparently .. I just used rems for text mostly and em's for static spacing
@gangasai_kumar_G
@gangasai_kumar_G Жыл бұрын
Can you create an angular new dev site home page animation , angular dev, if it is possible do a video on that, please consider as a serious request 🙏🙏🙏🙏🙏
@dimasmagadan
@dimasmagadan Жыл бұрын
what would you advice to use for breakpoints?
@KevinPowell
@KevinPowell Жыл бұрын
I used to say em, because it was the only one that was consistent across all browsers when zooming in/out, but Safari fixed their big, so em, rem, or px are all fine
@opletter
@opletter Жыл бұрын
What's the difference between using em vs % for font size?
@KevinPowell
@KevinPowell Жыл бұрын
Same thing, 1.5em = 150% for font size
@opletter
@opletter Жыл бұрын
@@KevinPowell Thanks! So is there a reason you suggest em specifically? Is that just more common?
@electronicmusicartcollective
@electronicmusicartcollective Жыл бұрын
THANX A LOT 🙏
@blizzy78
@blizzy78 Жыл бұрын
you should embed this video on the website as well
@KevinPowell
@KevinPowell Жыл бұрын
No idea why I didn't think of that 😅
@blizzy78
@blizzy78 Жыл бұрын
@@KevinPowell glad I could help 🙃
@axMf3qTI
@axMf3qTI Жыл бұрын
Wait, we don't define a root font-size in px in the :root?
@KevinPowell
@KevinPowell Жыл бұрын
That will overwrite user styles at the browser level, if they've set any up as a default, and is seen as bad practice.
@axMf3qTI
@axMf3qTI Жыл бұрын
@@KevinPowell So can I put a relative size in the root? Sometimes you want to make all your fonts bigger or smaller depending the type of screen or should we use a clamp for that?
@thats-tuff9678
@thats-tuff9678 Жыл бұрын
Awesome!
@noskillzdad5504
@noskillzdad5504 Жыл бұрын
More charts!
@Applecitylightkiwi
@Applecitylightkiwi Жыл бұрын
If this only is for positioning
@turtles_lover
@turtles_lover Жыл бұрын
NICE!
@kevinfisher7032
@kevinfisher7032 Жыл бұрын
Pica's! "Now that's a name I haven't heard in a LONG time" (Let Obi Wan and I go search for my pica ruler :-)
@KevinPowell
@KevinPowell Жыл бұрын
Glad I'm not the only one who has one lying around somewhere 😅
@rumbazumba3189
@rumbazumba3189 Жыл бұрын
Should have just made everything point back to rem eventually:D
@marble_wraith
@marble_wraith Жыл бұрын
If it's a flowchart... it should be able to be a VScode plugin for "suggestions". Just saying 😏
@DevoutJourney
@DevoutJourney Жыл бұрын
Not to sound like an asshole but, the irony is here. Clicked the link on mobile and its absolutely terrible. The newsletter link, and the flowchart itself, if you accidentally scroll past it, it’s like it’s gone forever hahahahahaha. Anyways, I like the concept.
@nikilragav
@nikilragav Жыл бұрын
I just use px, %, ch
@KevinPowell
@KevinPowell Жыл бұрын
No `rem`? :(
@nikilragav
@nikilragav Жыл бұрын
@@KevinPowell rem is certainly a reasonable thing to use. I just typically don't.
@nikilragav
@nikilragav Жыл бұрын
@@KevinPowell em I skip because it's relative to parent and you can get some very funky results (eg where you get font sizes inside a container that aren't one of your global scale)
@nikilragav
@nikilragav Жыл бұрын
@@KevinPowell here's why I think rem isn't necessary: the browser CSS px are NOT the same as your display's px. They are virtually pixels based on your device's DPI scaling settings and also on the percent scale level on your browser for the page. As long as you set all your sizes in 1 place and use CSS variables (thus restricting developers only to use your allowed values), rem and px produce the same effective result. I just think px are easier to understand vs ratios. Yes, some people set their default font size bigger or smaller than the default 16px. But honestly, it seems like a lot more people just zoom the page. I do that myself: I've set my Mac OS view to "More space" and most pages I've set to 80% (so even smaller haha 🤣).
@mrgamerzyt3945
@mrgamerzyt3945 Жыл бұрын
love from pakistan
@fersahahmet9597
@fersahahmet9597 Жыл бұрын
I want a flexbox and dont want children fluid is like i wanna take a shower but i dont wanna get wet
@atlantic_love
@atlantic_love Жыл бұрын
This is what's stopping me from learning CSS. It's a MESS!!!
@harunjonuzi
@harunjonuzi Жыл бұрын
Is like the other stuff is way too simplified 😂😂😂
@atlantic_love
@atlantic_love Жыл бұрын
@@harunjonuzi I'm not sure I get what you're saying.
@harunjonuzi
@harunjonuzi Жыл бұрын
@@atlantic_love it's fine brother, i hope you have a wonderful weekend!
@atlantic_love
@atlantic_love Жыл бұрын
@@harunjonuzi Oh, okay, so you were trying to be clever and failed. The other stuff is just fine, CSS is a mess. Else, you wouldn't need a "flowchart just to navigate it".
@esgn.design
@esgn.design Жыл бұрын
Holy shit dude just use rem lol
CSS unit Tier List
28:00
Kevin Powell
Рет қаралды 28 М.
Using CSS custom properties like this is a waste
16:12
Kevin Powell
Рет қаралды 185 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Easily create overlapping sections on a website
11:20
Kevin Powell
Рет қаралды 33 М.
Under the radar CSS features for your CSS reset
11:41
Kevin Powell
Рет қаралды 50 М.
CSS Anchor Is The Best New CSS Feature Since Flexbox
15:39
Web Dev Simplified
Рет қаралды 379 М.
px vs rem: what to use for font-size in your CSS
16:11
Coder Coder
Рет қаралды 51 М.
CSS position deep dive
28:14
Kevin Powell
Рет қаралды 112 М.
Can I clone this rotating, gradient, inner glow effect?
23:05
Kevin Powell
Рет қаралды 53 М.
CSS Clamp Simplified, with Fluid Responsive Typography Examples
9:19
Deeecode The Web
Рет қаралды 8 М.
CSS Popover + Anchor Positioning is Magical
20:44
Kevin Powell
Рет қаралды 52 М.
Learn flexbox the easy way
34:04
Kevin Powell
Рет қаралды 735 М.