HTML & CSS for Absolute Beginners: Font sizes

Kevin Powell · Beginner ·🌐 Frontend Engineering ·1y ago
Skills: HTML & CSS90%

Key Takeaways

This video teaches HTML and CSS basics, specifically font sizes, using CSS units such as pixels and rem, and demonstrates how to create a scalable font size using rem units.

Full Transcript

so this lesson's about font sizes and font sizes are a simple thing but they open up a bit of a can of worms because they open up length units in CSS because we have lots of available length units to us for example uh let's we'll just do it here so we see it and the big impact this can have and we'll do a font size on here and I could say the font size is 1 cm s CM for centimeter that is a centimeter like you'd expect and the fonts get much bigger and so we have C we have inches which would obviously make this gigantic uh so we can measure things in inches uh and there's other of like actual measurement things that you might use which we don't want to actually use in CSS unless of course you're creating something for print cuz you can make things for print with CSS as well uh and the most common unit you will see in CSS is the pixel so I could say the font size is 20 pixels and then that will be setting the font size of my paragraphs the headings will sort of scale up from there uh because of the user agent styles that are on them they're set to always be bigger than the font size you're setting here so I'm saying This is 40 pixels right now and my font size is getting bigger this is the most straightforward unit because it's what most design software uses it's if you're used to like Google Docs or anything else the font sizes are usually set in pixels and so it becomes the easiest unit to be able to use and for most things we're going to get into you can make the size of things like set the width and the height elements and setting those in pixels is probably fine however there's a problem with pixels on font size and that it's bad practice you should never do this and the reason for that is users can go into their browser settings and they can actually change the size of the font being used and if you come in and you say that my font size is 10 pixels like this if the user set a different standard on the size being used it's probably because they like they or they need bigger font sizes and if you set this at 10 pixels it will be 10 pixels this is an an absolute unit the same way something is 10 cm is 10 cm like it's a fixed unit that you could actually measure and it's linked to the size of an inch actually uh that's the other weird thing with pixels a CSS pixel is not a screen pixel if it was it would be a nightmare because different screens and monitors have different pixel sizes and so then a pixel would always be different and it would be very hard to do anything and it would be basically useless so first of all a pixel a CSS pixel a fixed unit size and it overwrites the user preference and if a user gets here and they have a very small font size and that's not what they want they could zoom in but they'll probably just leave and go somewhere else CU your site's probably not the only one that's you know what they were looking for there's probably competitors and if somebody else is doing it better then they're going to prefer that one and it's just generally considered best practice to not do this like pixels as font sizes are just one of the big no no that a lot of it's like the easy one to learn so this is the unit you'll learn at the beginning and then after that you have to break that habit I don't I just want to set you up with the right habit from the beginning and the right habit is to use a unit called a rem like this so one REM uh what is a rem this opens up a bit of a can of worms on its own because it's sort of there's an M unit as well that I'm not even going to talk about in this course uh the REM is based on the root and the root of our project is sort of like we have our root for folder so if we look here the root folder is where our project is living the root m is basing its font size on the root element and the root element is the HTML element CU everything is the child of my HTML element and the way REM units work is it's basically a scale it's saying that if you have one REM you're matching the font size of the HTML element so I'm going to do something you shouldn't actually do now but it's just going to illustrate how Rems work so let's take this one off of the body and refresh nothing should change and we're going to come on the H1 here and I'm going to say my H1 has a font size of one r instead and it's going to get a lot smaller so we can see it right there now I'm going to come all the way up and say my HTML element has a font size of uh let's say 25 pixels and I put refresh you can see this got bigger so this one REM is now equal to 25 pixels if I make this uh 45 pixels now and and I refresh now the font size here is one REM so it's the same as the 45 pixels here if I were to make this two REM that means it's 2 * 45 so it's going to be double the size or now it's becoming 90 pixels so whenever we do REM it's a scaled value of what our HTML elements font size is that leads to the question of if we don't declare a font size on the HTML what is the default font size and that's where the default if a user has not changed their user preference the default is 16 so that would be if you had this this would be what everything looks like but once again if you did this this would be overwriting a user's preference which we don't want to do so you generally don't declare a font size on your HTML element and you just let it stay at the default value and so the default value of that will be 16 though if a user changes their preferences it could be larger or technically smaller than what that 16 is so we don't always know exactly what the font size is but that's fine that's part of designing websites is we don't know anything that the user is doing we don't know how big their screen is how small it is are they on a phone or they on a TV or anything in between and we have to create websites can adapt to all of these different scenarios and getting used to using the right units with our font sizes is a really good way to or just start living in that reality that we have no control over things so uh what I'm going to do is actually just suggest that you come through and do your best just to try and like match it closely enough uh if you're working on a more formal design you would have like potentially actual values that you should be using and it's weird working off of a base 16 when you're using REM I won't lie but you get used to it really quickly so if I just you know I look at this and this needs to be really big I just go in my heading here and I can say font size is I don't know five R and then I can refresh and see what that looks like hey that's not too bad it's not exactly the same size but it's quite big my you know maybe it needs to be a bit bigger I can try a 5.5 if I want to and then see what that looks like I can make it a 7.5 and I just want for now just go through and try and Eyeball things until they look half decent and if you find it's too big or too small then just make adjustments and find numbers that you think are going to work uh and that look good I'm not we're not going to get too specific or too picky with it the one thing I will say is once again you can set font sizes on your body so that could actually be a good starting point is instead of starting on the H1 coming and doing a font size I often do like a 1.25 uh on the body CU if I do that it just makes the font size a little bit bigger so something like that uh getting bigger than 1.25 here tends to get quite big for regular text but again it depends on the layout you can use different fractions or different decimals here to get a size that you think works well uh and just go through and add in the different font sizes that you want to be using to try and just eyeball it as closely as you can with the design and just remember remember it's all just sort of based on ratios my you know this is smaller my H1 will be quite big my H2S will probably be somewhere in the middle and then you just go from there and I think that's a good start for getting used to using REM units

Original Description

🎓 Enroll in this course for FREE - get additional lessons, written content, interactive exercises, and more: learn.kevinpowell.co 📂 Get the course files here: https://www.dropbox.com/scl/fo/kusdjekuytcaa3of0vtd4/AChRHcF13pNi93JWusfLW9A?rlkey=tbrbxnabsi52u6onal9rh7fwm&st=iyo2wujq&dl=0 Learn to build websites from scratch - even if you've never written a line of code before. This hands-on course teaches you the fundamentals of HTML and CSS, the building blocks of the web. You'll start with the basics and progress step-by-step to creating your own responsive websites. Perfect for complete beginners who want to start their web development journey. #css -- Come hang out with other dev's in my Discord Community 💬 https://discord.gg/nTYCvrK Keep up to date with everything I'm up to ✉ https://www.kevinpowell.co/newsletter Come hang out with me live every Monday on Twitch! 📺 https://www.twitch.tv/kevinpowellcss --- Help support my channel 👨‍🎓 Get a course: https://www.kevinpowell.co/courses 👕 Buy a shirt: https://teespring.com/stores/making-the-internet-awesome 📽️ Join as a channel member: https://youtube.com/@KevinPowell/join 💖 Support me on Patreon: https://www.patreon.com/kevinpowell or through YT memberships: Join this channel to get access to perks: https://www.youtube.com/channel/UCJZv4d5rbIKd4QHMPkcABCw/join --- My editor: VS Code - https://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 YouTube channel, make sure to follow me on Instagram and Twitter. Bluesky: https://bsky.app/profile/kevinpowell.co Codepen: https://codepen.io/kevinpowell/ Github: https://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!
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Kevin Powell · Kevin Powell · 0 of 60

← Previous Next →
1 How to create an awesome navigation bar with HTML & CSS
How to create an awesome navigation bar with HTML & CSS
Kevin Powell
2 Improve your CSS by Keepin' it DRY
Improve your CSS by Keepin' it DRY
Kevin Powell
3 HTML & CSS for Beginners Part 6: Images
HTML & CSS for Beginners Part 6: Images
Kevin Powell
4 HTML & CSS for Beginners Part 7: File Structure
HTML & CSS for Beginners Part 7: File Structure
Kevin Powell
5 HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
Kevin Powell
6 HTML & CSS for Beginners Part 5: Links
HTML & CSS for Beginners Part 5: Links
Kevin Powell
7 HTML & CSS for Beginners Part 3: Paragraphs and Headings
HTML & CSS for Beginners Part 3: Paragraphs and Headings
Kevin Powell
8 HTML and CSS for Beginners Part 1: Introduction to HTML
HTML and CSS for Beginners Part 1: Introduction to HTML
Kevin Powell
9 HTML and CSS for Beginners Part 2: Building your first web page!
HTML and CSS for Beginners Part 2: Building your first web page!
Kevin Powell
10 HTML & CSS for Beginner Part 8: Introduction to CSS
HTML & CSS for Beginner Part 8: Introduction to CSS
Kevin Powell
11 HTML & CSS for Beginners Part 9: External CSS
HTML & CSS for Beginners Part 9: External CSS
Kevin Powell
12 HTML & CSS for Beginners Part 10: Divs & Spans
HTML & CSS for Beginners Part 10: Divs & Spans
Kevin Powell
13 HTML & CSS for Beginners Part 11: Classes & IDs
HTML & CSS for Beginners Part 11: Classes & IDs
Kevin Powell
14 HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
Kevin Powell
15 HTML & CSS for Beginners Part 13: Background Images
HTML & CSS for Beginners Part 13: Background Images
Kevin Powell
16 HTML & CSS for Beginners Part 14: Style Text with CSS
HTML & CSS for Beginners Part 14: Style Text with CSS
Kevin Powell
17 HTML & CSS for Beginners Part 15: How to style links
HTML & CSS for Beginners Part 15: How to style links
Kevin Powell
18 HTML & CSS for Beginners Part 16: CSS selectors and Specificity
HTML & CSS for Beginners Part 16: CSS selectors and Specificity
Kevin Powell
19 HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
Kevin Powell
20 HTML & CSS for Beginners Part 18: How Floats and Clears work
HTML & CSS for Beginners Part 18: How Floats and Clears work
Kevin Powell
21 HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
Kevin Powell
22 HTML & CSS for Beginners Part 20: How to center a div
HTML & CSS for Beginners Part 20: How to center a div
Kevin Powell
23 HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
Kevin Powell
24 HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
Kevin Powell
25 How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
Kevin Powell
26 How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
Kevin Powell
27 How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
Kevin Powell
28 How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
Kevin Powell
29 How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
Kevin Powell
30 Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Kevin Powell
31 End of the year upate and what's coming to my channel to start the new year
End of the year upate and what's coming to my channel to start the new year
Kevin Powell
32 Create a CSS only Mega Dropdown Menu
Create a CSS only Mega Dropdown Menu
Kevin Powell
33 CSS Tutorial: Outline and Outline Offset
CSS Tutorial: Outline and Outline Offset
Kevin Powell
34 CSS Blending Modes
CSS Blending Modes
Kevin Powell
35 Parallax effect | 2 different ways to add it with jQuery
Parallax effect | 2 different ways to add it with jQuery
Kevin Powell
36 CSS Units: vh, vw, vmin, vmax #css #responsive #design
CSS Units: vh, vw, vmin, vmax #css #responsive #design
Kevin Powell
37 How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
Kevin Powell
38 100 Subscribers speed coding bonus video
100 Subscribers speed coding bonus video
Kevin Powell
39 How to Create a Website - Complete workflow | Part 02: The Markup #HTML
How to Create a Website - Complete workflow | Part 02: The Markup #HTML
Kevin Powell
40 How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
Kevin Powell
41 How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
Kevin Powell
42 How to Create a Website - Complete workflow | Part 05: Typography & Buttons
How to Create a Website - Complete workflow | Part 05: Typography & Buttons
Kevin Powell
43 How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
Kevin Powell
44 How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
Kevin Powell
45 Redesigning & Coding My Website #CreateICG
Redesigning & Coding My Website #CreateICG
Kevin Powell
46 How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
Kevin Powell
47 How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
Kevin Powell
48 How to Create a Website - Complete workflow | Part 09: The CTA and Footer
How to Create a Website - Complete workflow | Part 09: The CTA and Footer
Kevin Powell
49 How to Create a Website - Complete workflow | Part 10: Making it responsive
How to Create a Website - Complete workflow | Part 10: Making it responsive
Kevin Powell
50 How to Create a Website - Complete workflow | Part 11: Making it responsive con't
How to Create a Website - Complete workflow | Part 11: Making it responsive con't
Kevin Powell
51 How to Create a Website - Complete workflow | Part 12: Putting the site online
How to Create a Website - Complete workflow | Part 12: Putting the site online
Kevin Powell
52 Create a Custom Grid System with CSS Calc() and Sass
Create a Custom Grid System with CSS Calc() and Sass
Kevin Powell
53 CSS em and rem explained #CSS #responsive
CSS em and rem explained #CSS #responsive
Kevin Powell
54 Should you use Bootstrap?
Should you use Bootstrap?
Kevin Powell
55 How to add Smooth Scrolling to your one page website with jQuery
How to add Smooth Scrolling to your one page website with jQuery
Kevin Powell
56 Let's learn Bootstrap 4
Let's learn Bootstrap 4
Kevin Powell
57 How I approach designing a website - my thought process
How I approach designing a website - my thought process
Kevin Powell
58 Build a website with Bootstrap 4 - Part 1: The setup
Build a website with Bootstrap 4 - Part 1: The setup
Kevin Powell
59 Build a website with Bootstrap 4 - Introduction
Build a website with Bootstrap 4 - Introduction
Kevin Powell
60 Build a website with Bootstrap 4 - Part 2:  Customizing Variables
Build a website with Bootstrap 4 - Part 2: Customizing Variables
Kevin Powell

This video teaches beginners how to work with font sizes in HTML and CSS, covering topics such as rem units, pixels, and relative sizing, and demonstrates how to create a scalable font size.

Key Takeaways
  1. Try to match font sizes closely enough
  2. Use rem units to create a scalable font size
  3. Set font sizes on the body element to create a base size
  4. Use different fractions or decimals to get a size that works
  5. Add different font sizes to try and eyeball the design
  6. Use fractions or decimals for font sizes
💡 Using rem units for font sizes allows for relative sizing and scalability, making it a better practice than using absolute units like pixels.

Related Reads

📰
The “Wiz” Merger: How Google’s Internal Framework is Rewriting Angular
Learn how Google's internal framework is improving Angular with server-side rendering and hydration
Medium · JavaScript
📰
Day-3 of Posting blog (Lists in html)
Learn to create ordered and unordered lists in HTML to structure content effectively
Dev.to · antony stark
📰
I Built a 100% Free, Frictionless Resume Builder with Direct PDF/Word Exports
Learn how to build a free and frictionless resume builder with direct PDF and Word exports, and discover the tools and techniques used to create it
Dev.to · Solangi Waqas
📰
How to Deploy Angular SSR on Cloudflare Workers for Free — No VPS, No Fees, No Credit Card.
Learn to deploy Angular SSR on Cloudflare Workers for free without needing a VPS, fees, or credit card
Medium · JavaScript
Up next
Elementor Angie Ai Plugin Tutorial
Quick Tips - Web Desiign & Ai Tools
Watch →