CSS Tutorial — How to use Fonts (12/13)
All you gotta do to change the font of your page is decide what font you wanna use, say Roboto and write font-family: Roboto… Really? No... not really, it’s more complicated than that.
Typography is a gigantic topic in web design and of course you have a ton of options in CSS to better your font styles and its readability. Now this isn’t a design course, so I won’t be covering design theory, I’m not gonna tell you what looks good and what doesn’t, but I will show you how to manage your fonts in HTML/CSS.
You can use fonts that already exist on your computer and everybody else’s computers like “Times New Roman” or “Arial”, these are generic “WEB SAFE” fonts, but they’re limited and honestly kinda boring. Or you can use what’s called a custom font.
There are a ton of custom fonts out there. If you’re a designer you have definitely worked with custom fonts so you know what I’m talking, you’re also not gonna like what I’m about to say. I am not a huge fan using custom fonts for websites Not because they’re not cool or pretty.
But for one thing, not all browsers render custom fonts the same way or even correctly, so you potentially run that risk. Also, using custom fonts means anybody going to your site has to wait for the browser to download the custom font first, then render the site. Where as with generic fonts it doesn’t. And that’s costly, it takes time and bandwidth. Lastly, a huge proportion of custom fonts are great for banners and flyers and quotes (SHOW INSTAGRAM QUOTE, SHAKE HEAD), but they are absolutely awful for long body text like articles. Their readability is not always the best. With all that said, a lot of people still use them for many different reasons. Trust me, I understand the importance of uniqueness and personality when it comes to design, in fact ColorCode’s website uses a custom font on the hero page, but it comes at a cost.
Custom fonts are like a chocolate milkshake. They’re sooo amazing but you really shouldn’t be doing it, unless you are willing to pay the price…
Anyway,...I still want you to know how to change fonts.
There are 2 things you need to do. Load or “EMBED” the font into the page (assuming it’s a custom font, for generic fonts you can skip this step), THEN change the font-family property in your CSS.
How do you load fonts? Using a LINK tag in your HTML… OR…. an @import or @Font-Face statement in your CSS to point to the location of that font. It could be loaded from anywhere on the internet and I’ll show you an example in a second. Again, if you’re using a default font, you don’t need to load anything, because Arial is already available on everybody’s computer/phone/iPad, etc...
So,...we’re gonna get some help from our friends over at google fonts to demo this. So head over to fonts.google.com and I’ll show you how.
So here it is, a long list of custom fonts for you, pick one and look at the instructions. So I’m gonna pick Roboto and look, it even generates the code for you to embed and then set the font-family. Notice the embed part can be done in a couple of different ways, also the CSS font-family statement can take multiple values separated by a comma. This means hey, Mr. Browser, if you can’t find the first one for whatever reason, cuz it’s a fancy one, go to the next one, if you can’t find that one either, keep going until you get to one that you CAN render. You always wanna have backups in case your custom font can’t be loaded.
So, in the next video I’m gonna update our Profile page to use Google Fonts. It’ll be our last demo in this course and it’ll instantly make our page look much more professional, see you there.