Are you using the right CSS units?

  Переглядів 437,406

Kevin Powell

Kevin Powell

День тому

There are a lot of different units that we can use when writing CSS, in this video I give some general rules of thumb of which ones are best suited for which situations.
Zell's article on media queries: zellwk.com/blog/media-query-u...
Em vs. Rem: • CSS em and rem explain...
Using clamp() for fonts: • min(), max(), and clam...
The issue with em with font sizes: • Why you shouldn't set ...
Viewport units: • CSS Units: vh, vw, vmi...
The ch unit: • The ch unit is the mos...
#css
--
Come hang out with other dev's in my Discord Community
💬 / discord
---
Keep up to date with everything I'm up to
✉ www.kevinpowell.co/newsletter
---
Help support my channel
👨‍🎓 Get a course: www.kevinpowell.co/courses
👕 Buy a shirt: teespring.com/stores/making-t...
💖 Support me on Patreon: / kevinpowell
---
My editor: VS Code - code.visualstudio.com/
---
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 UKposts channel, make sure to follow me on Instagram and Twitter.
Instagram: / kevinpowell.co
Twitter: / kevinjpowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!

КОМЕНТАРІ: 463
@einfachnurlegendar7947
@einfachnurlegendar7947 3 роки тому
Summary: font-size: rem width: % in combination with a max-width, ch height: question urself "do i rly need to set height" if yes -> use a min-height padding/margin: rem or em, kevin often uses em for padding of buttons media queries: em px only for little things like shadows, borders etc. Great Video :)
@kedigiller111
@kedigiller111 3 роки тому
Just I'm looking for this, thanks :D
@JErock25
@JErock25 3 роки тому
Thank you!
@colindante5164
@colindante5164 2 роки тому
Thanks ))
@DilshanPuwanendran
@DilshanPuwanendran 2 роки тому
thanks mate
@tabhesab3555
@tabhesab3555 2 роки тому
Thanks
@TheBigCheez365
@TheBigCheez365 3 роки тому
This is such a solid channel. Literally my go-to for any and all things CSS. You da man Kevin.
@yasuekko8814
@yasuekko8814 3 роки тому
Indeed 🔥
@ErikZettersten
@ErikZettersten 3 роки тому
Second this
@juanmartinguillen4876
@juanmartinguillen4876 3 роки тому
I concord
@robs257
@robs257 2 роки тому
I agree
@dr_corrupt1014
@dr_corrupt1014 Рік тому
kevin you are the man!
@andreschavarria7091
@andreschavarria7091 3 роки тому
Ok so I’m 37 years young and decided to learn html/css with absolutely 0 experience and knowledge about coding or programming. Your channel has made things way easier for me to understand. So I guess I just want to say thank you and recognize the importance of sharing and the impact you’re making.... thanks!
@toddhoward5947
@toddhoward5947 3 роки тому
All the best man ❤
@samuelgoncalves5616
@samuelgoncalves5616 3 роки тому
Love that you are trying to learn! That's the way to go. Just out of curiosity, why did you start learning?
@rellison68
@rellison68 3 роки тому
Hi Andres. I am 52 and am returning to development after about 10 years off. I really appreciate channels like this to help out. Good luck!
@andreschavarria7091
@andreschavarria7091 3 роки тому
@@rellison68 thanks Robert, and good luck to you too! Agree with you, channels like this show some of the greatest benefits of platforms like UKposts... sharing IS caring
@andreschavarria7091
@andreschavarria7091 3 роки тому
@@samuelgoncalves5616 thanks Samuel! My wife started doing volunteering at her job, but one requirement is that whoever they’re volunteering for, must have a website and must of them don’t have one... so I said to her... I can build them a website, I’m sure that’s easy! Ha, little did I know... lol. And so I started learning literally 32 days ago. It’s a win win situation, they get the website and I get to learn.
@jackr9122
@jackr9122 3 роки тому
Kevin thank you so much man - the clarity I get from these videos is unreal. Keep it up, my friend!
@lordyc8393
@lordyc8393 2 роки тому
I discovered this channel a few days ago, I learned more about mobile responsive design than anywhere else and feel more confident using CSS. Kevin, you're a real one
@TheMatcap1
@TheMatcap1 3 роки тому
After deploying some sites on html and css i started watching your tutorials and i´m totally impressed, you really helped me a lot improving my css styling an writing. Thanks!
@kiggi__
@kiggi__ 3 роки тому
I am playing catch up with everything HTML, CSS, Javascript. Your video's are fantastic at helping me get to grips with all that has changed, keep up the awesome content!
@maitolehrer2613
@maitolehrer2613 3 роки тому
I've been looking for this kind of video for a long long time now. Thank you so much for this!
@patriknordberg1259
@patriknordberg1259 3 роки тому
I think you missed out on CSS Grid and using fractions or fr. Which I think should be very relevant at this time. People really need to start embracing CSS Grid as it makes your layout so much cleaner and allows you to keep your HTML semanticly correct. Appreciated the comment about ch. I hadn't used that so much and it really makes sense for column sizes.
@antoniomasotti8060
@antoniomasotti8060 Рік тому
I love this man and his videos. You see immediately how experienced he is and still humble and willing to help. And the advices are always top, they greatly improved the way I use css.
@cmyk8964
@cmyk8964 2 роки тому
For basic HTML games, I define a custom variable in the root relative to the viewport width/height (e.g. min(4vw, 3vh)) and calc everything else relative to that
@erichobbs4042
@erichobbs4042 3 роки тому
I learned about Ch from one of Kevin's other video's last year. It's my go to unit for designing text layout now.
@TheJacklwilliams
@TheJacklwilliams 2 роки тому
The ironic thing, as newb, I've used pixels for most everything because? I haven't the slightest idea of the definition and proper usage of the units you mentioned... Which of course, calls out the immediate need for me to, learn them, and use them accordingly. Thanks for this Kevin. I'm enjoying your content very much.
@VasilyPavlik
@VasilyPavlik 3 роки тому
Man, after your videos I started to use REMs. And it's marvelous. Because you can change only one font-size for body in media-query. And that's all. It works like variables even in IE. Now I'm thinking in REMs everywhere. Our body default font size is 10px, so it's quite easy to calculate. But it's also easy to scale layouts for any screen size depends on media. Thank you a lot!
@tomasjsierra
@tomasjsierra 2 роки тому
After watching this I improved my site by a lot, I think. Such a big difference in just 6 minutes of video. Many thanks.
@lordyc8393
@lordyc8393 2 роки тому
Same!! made a new css which went from 1000 lines to 700 for my website
@theorycreative
@theorycreative 3 роки тому
Great video! It definitely gets confusing sometimes, especially if you’re hours into a project, getting tired and start making mistakes. I’m still a designer at heart, even though I’ve been writing code for decades, it’s not often enough to keep track of everything... and then throw math into the mix after a long day, d’oh!
@Reckless917
@Reckless917 3 роки тому
Amazing video as always. Super concise and well explained, thanks a lot!!
@TheMoonLayingLow
@TheMoonLayingLow 3 роки тому
This is so helpful! Thank you for sharing your knowledge, Kevin.
@troelsrasmussen7457
@troelsrasmussen7457 3 роки тому
Realy nice example with the button where padding is defined using em! Good job and nice videos - thanks!
@necroowl3953
@necroowl3953 2 роки тому
Thanks a lot, Kevin, your videos are awesome and very complete. This used to be super boring to me, and your content got me interested in actually learning SCSS.
@aceandember
@aceandember 2 роки тому
So, today something clicked and I owe it all to you Mr Powell. I have been doing CSS/SCSS almost every day for a few years but I didn't grasp the concept of parent height affecting the height of children until I watched one of your videos (you do great btw, ty). I struggled with dealing with it for a long time and today I was tackling a typical challenge, one where a div dynamically pops up from the bottom and I had to size the content above so that it could handle a custom scrollbar etc. Anyway, due to your videos, I walked it through and it worked the first time! Often I'd struggled over this similar scenario with other elements and had to guess, refresh, and just sort of luck my way into it. Now I get it! TY TY TY!!
@Springfielde
@Springfielde 3 роки тому
I really like that you add your face to your content. It makes things much more direct, so it's easier to learn. :)
@Priority64
@Priority64 3 роки тому
In addition to awesome content you put out constantly, I also have to admire that your videos are CRISP! Love that not only your content is hiqh quality but your video quality too.
@asdfasdfsdflk
@asdfasdfsdflk 2 роки тому
This is so useful for how short it is; I really appreciate this content.
@wickedwifestre
@wickedwifestre 2 роки тому
this was extremely helpful. i’m pretty new to css so this gives me a lot of good stuff to think about. thank you!
@arceniocornejo6779
@arceniocornejo6779 3 роки тому
I'm trying to learn more about css "little tiny details" for many years. I know your videos will be helpful to learn the subtle details hidden in this languages. Thanks very much for your efforts to disseminate these important techniques. PD I am a retired professor from Panama.
@Coco-ii2pu
@Coco-ii2pu Рік тому
You're the best tutor online Kevin. And somehow you have all the answers 😂. Thank you
@dimitrys.2494
@dimitrys.2494 3 роки тому
i thought you had like a million plus followers. you are my go to guy if i don't understand something in css. let's try and bring you to at least half a mil. i'm sharing for sure all the time ! you go man!
@cmdaltctr
@cmdaltctr 3 роки тому
THANK YOU THANK YOU! I have been wondering about this as a beginner and this helped me termendously!
@doubledeckercouch6251
@doubledeckercouch6251 3 роки тому
Excellent video - and something which needed a quick reference point to "flick back to". Thanks Big K :)
@lieutenantlascivious1992
@lieutenantlascivious1992 2 роки тому
Thank you so much! I learn so many little tricks and get so many great suggestions from your videos!
@MasayaShida
@MasayaShida 3 роки тому
Thanks so much for this I'm always insecure about what units to use
@CodingNuggets
@CodingNuggets 3 роки тому
The CSS GOAT bringing everyone some very useful info. Appreciate you Kevin. See you soon!
@penggunayoutube2580
@penggunayoutube2580 2 роки тому
I always check a video or two from this channel. All of them is really helpful in my road on web development learning Love your content
@nymusicman
@nymusicman 3 роки тому
Been a rem user for a long time and love it. First time learning about ch. I'm very excited to start using it in some of my websites.
@yahayaoyinkansola8258
@yahayaoyinkansola8258 2 місяці тому
Thank you so much Kevin for this particular video!, it really clarified a lot for me
@imluctor5997
@imluctor5997 3 роки тому
You can also make a function in scss to calculate the pixels to rem. I always use that and call the function px-to-rem() if you take this in use make sure you don't have to put a value with px at the end to make it faster to write it.
@rohitkf8474
@rohitkf8474 2 роки тому
Font size : use rem Width : coupled with max width, use ch unit(75 or less) Height : set min height Padding or margin : em(padding for buttons) or rem Medi queries : em
@0the0ambient0
@0the0ambient0 3 роки тому
Kevin ~ You are amazing . So much ambiguity yet you find clarity
@ru2979
@ru2979 2 роки тому
Sir .This is a ultimate web dev channel . Kudos to your hard work and love your videos ❤️☺️
@Brunoenribeiro
@Brunoenribeiro 3 роки тому
.kevin__coat { display: flex; justify-content: flex-start; }
@ivanberdichevsky5679
@ivanberdichevsky5679 3 роки тому
I think this has align-items: flex-end actually 😂
@akifcankara2225
@akifcankara2225 3 роки тому
.kevin__tshirt:nth-child(even){ background: pink; } .kevin__tshirt:nth-child(odd){ background: whitesmoke; } .kevin__tshirt:nth-child(3n){ background: grey; }
@sumitpurohit8849
@sumitpurohit8849 3 роки тому
.kevin__coat { align-items: space-between; }
@ari-mcbrown
@ari-mcbrown 3 роки тому
weird flex, but okay
@kblyr
@kblyr 3 роки тому
Awesome! This is really very helpful, thank you!
@90kidsgamezone76
@90kidsgamezone76 3 роки тому
You are the man who learn me a lot of love with css
@doug7897
@doug7897 3 роки тому
Due to writing a lot of wordpress stuff, I've avoided using the 62.5% font-size trick since that breaks certain styles in the admin. Instead I have a SASS function called rem(), which just takes whatever pixel value I want to have, and devides by 16 to convert to rems. Definitely a few more characters to type (painfully so), but I've honestly gotten used to it and outside of the awkwardness using them in things like long padding declarations, it's been pretty nice. Untill the designer uses inspector to figure out size adjustments and gives me values in REMs that I have to convert back to pixel values. Then it's hell.
@RahulKumar-jx5ku
@RahulKumar-jx5ku 2 роки тому
You are making my job easier, Kevin. Thank you very much for that.
@mrx-qi8th
@mrx-qi8th 3 роки тому
Nice,thanks for sharing your information. I've always clicked the like button even if i didn't have the time to watch it at the moment
@mikaockerman832
@mikaockerman832 Місяць тому
Our designers want things to look consistent across sizes, fully responsive, and they also make very complex designs. This means the headings, boxes, margins, padding all needs to adjust to screen size. I find myself using Calc with VW quite often. I don't know of that's the best way, but it has been working for me. I do use REM for font size whenever I can though. Thanks!!
@stevepiraud7629
@stevepiraud7629 3 роки тому
Awesome, like always!
@PaulNieman
@PaulNieman Рік тому
Brilliant and helpful advice. Thank you.
@ViorelMocanu
@ViorelMocanu 3 роки тому
My rules of thumb are: » % or vw for box widths » % or vh for box heights (indeed, rarely) » rem or em for font sizes, leadings, and other type-related dimensions (e.g. image sizes sometimes) » em for paddings and margins » px for border widths (especially when aiming for that 1px crisp) and media queries (will take a look at the article you recommended, but in principle, it worked well for me so far) and widths and heights (even if I override them in CSS in other units) » ch for paragraph max-widths
@jovanlaguitao3384
@jovanlaguitao3384 Рік тому
Very helpful Kevin thank you so much!!
@DANNFIGDESIGNS
@DANNFIGDESIGNS Рік тому
This was the video I was looking for. I know how the units work, but where to use them busted my brain. For the most part I was using vh and vw to much. Also, I was using em for my font sizes, and the parents all the way up were using em as well. Also the whole concept presented here will stick. Thank you Kevin. Big fan. Update: I read the article regarding the media queries and I'm curios if it's still relevant today. It definitely was written a long time ago. I'm using Webflow and was surprised to see them using px for media queries.
@PlayRiteProductions
@PlayRiteProductions 3 роки тому
Video is gold, thanks so much!
@tonybell1597
@tonybell1597 5 місяців тому
Thankyou! I’ve very recently arrived at coding a website for a group of people, having managed to avoid html, css and Java since Sir Tim B-L invented it! (Odd as I’ve been in this business for 40+ years) and now I’m here! Wow…. Thank you so much for your vids, they have been superb at explaining principles … keep up the grand work…
@AnandKumarChaudhary
@AnandKumarChaudhary 2 роки тому
Kevin has unparalleled skill of explaining highly complex concepts in very simple manner. Great Work!!!!
@mreclecticguy
@mreclecticguy 3 роки тому
Extremely helpful, thank you.
@Football__Junkie
@Football__Junkie 3 роки тому
Great video. Actionable and to the point
@guillermoandradaFSD
@guillermoandradaFSD 3 роки тому
Thank you so much... You channel is awesome
@stefanofrontani2220
@stefanofrontani2220 2 роки тому
So clear. You've just won a new subscriber.
@KevinPowell
@KevinPowell 2 роки тому
Welcome aboard!
@40ozTea
@40ozTea 8 місяців тому
Great explanation!
@snaydenoff
@snaydenoff 3 роки тому
Great video! As a product designer who has just started writing my own html/css, I find your videos really useful! It would be great for beginners if you could expand on the issues with examples, such as what issues using the viewport width would cause. ✌️
@thewadegreen
@thewadegreen 3 роки тому
Another great video topic! Thanks!
@shahshail12
@shahshail12 2 роки тому
Hey Kevin, your videos are awesome 👌, just wanted to ask you that is it a good practice to give margin top & bottom in vw?
@TheDMaciek
@TheDMaciek Рік тому
Thanks man! Great video
@A_Lesser_Man
@A_Lesser_Man 3 роки тому
css is the bane of my existence, you make it bareable!
@ax-coding631
@ax-coding631 2 роки тому
Really useful, thank you!
@huynh4128
@huynh4128 3 роки тому
This is the video i needed right now
@mabelwin4779
@mabelwin4779 Місяць тому
THANKS U SO MUCH❤😢WITH your videos, now I become understanding about front end working .the videos are right to the point and save time❤🎉
@tommy6322
@tommy6322 3 роки тому
I am not sure. But hopefully you will clear things up for me! :) Love your videos!
@williamboshi1855
@williamboshi1855 3 роки тому
This topic interested so much I liked before watching, I hope the algorithm gods noticed
@DrewBombard
@DrewBombard 2 роки тому
Just found Kevin last week. Wow… so awesome and easy to understand examples and tutorials and … just amazing.
@KevinPowell
@KevinPowell 2 роки тому
So glad you're enjoying my content!
@joulesgarcia400
@joulesgarcia400 3 роки тому
THANK YOU SO MUCH MAN!
@lostcarpark
@lostcarpark 2 роки тому
That's really helpful. I occasionally need to design things for print, and sometimes for label printers, so need to be able to control exact size on the page. I generally use cm or mm with media queries for these.
@KevinPowell
@KevinPowell 2 роки тому
I come from a print background, and the idea of using fixed units like that in CSS scares me so much, lol. But it does the job!
@lostcarpark
@lostcarpark 2 роки тому
@@KevinPowell Absolutely. I think in most cases fixed units are to be avoid. There are just occasions when something needs go to a printer, and needs to fit precise measurements. Mostly this will be for admin pages that end users will never see.
@troika_473h
@troika_473h 3 роки тому
Thank you for the video!
@Vreth6
@Vreth6 3 роки тому
You nailed the thumbnail on this one 😂
@georgiosg9464
@georgiosg9464 Рік тому
this cool person is the only one who making me enjoy his content , describe it as much as simple he can!
@haliszekeriyaozkok4851
@haliszekeriyaozkok4851 Рік тому
When ı wasn't know the difference between relative and absolute units ı used to the absolute units and because of that struggled with media queries. Thanks to Allah ı learned them and now my layouts even more responsive and ı don't use media queries too much.
@GR_BackingTracks
@GR_BackingTracks Рік тому
@ 4:21 is my favorite of the tips... I'm a brand newbie to this stuff and this seems perfect for the site I'm making.
@LuisReyes-zs4uk
@LuisReyes-zs4uk 3 роки тому
You're awesome, Kevin!
@vasiovasio
@vasiovasio 2 роки тому
Great video! Thank you!
@mountainslopes
@mountainslopes 3 роки тому
I like the idea of px for html font size (can change with breakpoints), rem for components, and em for elements within those components.
@KevinPowell
@KevinPowell 3 роки тому
For accessibility reasons, it's really important not to set the html font size with a pixel value. Assume the default is 16, and use a percentage. You can still scale that number up and down within breakpoints :)
@shivanshshalabh
@shivanshshalabh 3 роки тому
Hi! First of all thanks for this awesome video🙂. I have a question that whether we should use percentage as a unit for margin and padding or rem?
@mechmaverick
@mechmaverick 3 роки тому
literally subbing because the "ch" explanation
@maxwellandyaffanyi7499
@maxwellandyaffanyi7499 2 роки тому
🙌🙌🙌👏.... You be CSS bossu 🥳🥳 😄Kudos from Ghana🇬🇭
@juanmadelaflor6406
@juanmadelaflor6406 3 роки тому
Thanks Kevin!
@intelo6251
@intelo6251 3 роки тому
Just love this guy!
@TazExprez
@TazExprez Рік тому
Thanks a lot for this.
@angeh100
@angeh100 2 роки тому
helped me very much. thanks
@sundayuchegbu2060
@sundayuchegbu2060 3 роки тому
Hi Kelvin, have been going through your channel and you are simply amazing
@KevinPowell
@KevinPowell 3 роки тому
Thank you so much 😀
@claasgreeneye
@claasgreeneye 3 роки тому
I use pixels alot, thanks for sharing!
@kudaykumar1261
@kudaykumar1261 2 роки тому
Thank you so much sir.
@WizardOfArc
@WizardOfArc 3 роки тому
Thank you so much!
@dragonore2009
@dragonore2009 3 роки тому
Same here I don't use pixels as much anymore. For when I do use them, it's usually some margin left or right that needed 4px or something. The only big use I have for pixels is sometimes I will use them for min-widths where appropriate.
@chrislife1101
@chrislife1101 Рік тому
Kevin, I'm a dumbass, it's hard for me to pick up the simplest concepts, but idk how you do it. You just make my brain work with ur explanations. Currently following a Udemy course and alot of the properties etc are poorly explained, so I come here
@m12652
@m12652 3 роки тому
Excellent as always... Side tracking a bit, I recently moved back part-time onto Windows machines (well Macs running windows). what I noticed is that Microsoft like to mess with the zoom on your screen, I.e. ignore your resolution and display stuff at say 150% normal size (or whatever). This can make small images, like profile pics look terrible so I’m making them about 75% bigger than what the img size is set at. This does get a bit annoying with performance testing on google chrome for example as it nags about image sizes not being the same as their display size. I know we can have different images for different resolutions etc. but does that take into account the zoom level set by the OS?
@CharlesSmall
@CharlesSmall 3 роки тому
Thank you I never knew it at all.
@not_amanullah
@not_amanullah 2 місяці тому
This is helpful ❤
@micahhlc
@micahhlc Рік тому
the best CSS teacher in youtube.
@rammaheshwari9748
@rammaheshwari9748 3 роки тому
Very helpful video 👌
@mmelimahlobo7656
@mmelimahlobo7656 10 місяців тому
I am forever grateful for having such people like you,every time I am stuck with css I know you will be the solution to my problem may the Lord increase you more and more
Container queries are possible!
17:30
Kevin Powell
Переглядів 157 тис.
CSS em and rem explained #CSS #responsive
16:54
Kevin Powell
Переглядів 374 тис.
skibidi toilet 73 (part 2)
04:15
DaFuq!?Boom!
Переглядів 31 млн
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
Travis Media
Переглядів 485 тис.
Use these instead of vh
6:06
Kevin Powell
Переглядів 435 тис.
A CSS Unit Deep Dive - Learn CSS Units & When To Use Them
15:13
Slaying The Dragon
Переглядів 74 тис.
The problems with viewport units
13:23
Kevin Powell
Переглядів 349 тис.
Use Emmet to up your HTML game
11:22
Kevin Powell
Переглядів 65 тис.
23 CSS features you should know (and be using) by now
31:31
Kevin Powell
Переглядів 48 тис.
Design Better Than 99% of UI Designers
14:52
Tim Gabe
Переглядів 167 тис.
5 simple tips to making responsive layouts the easy way
15:54
Kevin Powell
Переглядів 734 тис.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Переглядів 876 тис.