Cory's profile picture

Published by

published
updated

Category: Web, HTML, Tech

🖥 CSS Snippet: Custom Fonts

OK gang, time to teach you how to use Google Fonts!


Step One: Go to Google Fonts and pick a font you like. I think Josefin Sans is pretty classy, so we'll use that one as an example.

Step Two: On the font page, click "Select This Style" on what you want. If you want to just use the font for titles/headlines, pick just one. If you want to use one font for your entire page, I would suggest picking a regular one, a bold one, an italic one and a bold italic one. 

SIDEBAR! Fonts are generally categorized into weights so to typographers, they have a little more flexibility with their fonts other than just regular and bold. So you might have 100 which would be super light, or 900 would be super duper thiccccc. Just a note.

For this example, I'll pick Light 300, Light 300 Italic, Bold 700 and Bold 700 Italic, just to cover all my bases. I'll click the link that says "+ Select This Style" next to all four. A sidebar thing should pop up letting you know you selected the fonts.

Step Three: Under the section that says "Use for the Web" click the radio button labeled "@import" and copy the code in the box. For me, the code looks like this:

<style>
@import url('https://fonts.googleapis.com/css2?family=Josefin+Sans:ital,wght@0,300;0,700;1,300;1,700&display=swap');
</style>

That's a lot of code bullshit, and it looks scary, but I got you, boo thang. Paste that shit in one of your profile boxes. You'll also want to pay attention to the box that says "CSS rules to specify families" because that's important. For this font it says

font-family: 'Josefin Sans', sans-serif;

so we'll keep that safe too.

Step Four: Let's target some elements! Do you want just the whole page to have your font? That one's easy. Right before the </style> tag, put in this line of code, using the CSS rules we grabbed in Step 3:

body{font-family: 'Josefin Sans', sans-serif;}

And you're done! Your completed code should look like this:

<style>
@import url('https://fonts.googleapis.com/css2?family=Josefin+Sans:ital,wght@0,300;0,700;1,300;1,700&display=swap');
body{font-family: 'Josefin Sans', sans-serif;}
</style>

If you want to target just headlines, use this code instead:

h1, h2, h3, h4 {font-family: 'Josefin Sans', sans-serif;}

And that'll get just the headlines.

More Reading: Here's more reading about Google Fonts from W3Schools if you need more info. Feel free to leave comments if you need help!


285 Kudos

Comments

Displaying 20 of 40 comments ( View all | Add Comment )

seo

seo's profile picture

this would be great if the cdn that spacehey uses wasn't made of shit, it recognizes 5% of the fonts i shove into it T_T


Report Comment

benjistyles19

benjistyles19's profile picture

HOW


Report Comment

brainsdotio

brainsdotio's profile picture

ur a literal lifesaver tysm :)


Report Comment

wirem0ther

wirem0ther's profile picture

thank youuuu! do you know if this works on blog posts or at all or just on your actual profile?


Report Comment

wirem0ther

wirem0ther's profile picture

thank youuuu! do you know if this works on blog posts or at all or just on your actual profile?


Report Comment

DJM1NT3

DJM1NT3's profile picture

shout out to vroski for giving us the best!!


Report Comment

valisyKoO

valisyKoO's profile picture

OMG, thank u sooo much, i cry with happiness T.T


Report Comment

kitty chan ~

kitty chan ~'s profile picture

thank you so much omg!!!


Report Comment



it worked for you?? i cant make it work :(

by Kitty; ; Report

A1RY

A1RY's profile picture

Thx so much worked like a charm bro


Report Comment

cена ♰

cена ♰'s profile picture

works wonders, thx man! kudos 2 you :)


Report Comment

VertigoMindwarp

VertigoMindwarp's profile picture

I'm using it now, many thanks! :)


Report Comment

Hannoi 

Hannoi 's profile picture

It worked thx!!!!

But one question: How do you change the size of the font?


Report Comment

Serafina.ᐟ ₍ᐢ. .ᐢ₎‧₊˚✩彡

Serafina.ᐟ ₍ᐢ. .ᐢ₎‧₊˚✩彡's profile picture

My code didn't work so i thought i was doing smth worng, so i put in the code u used for the example and it didn't work either :(


Report Comment

Edd

Edd's profile picture

Its not working?? help??


Report Comment



Can you send the text you put? I might be able to help out

by Lucia ᖭ༏ᖫ; ; Report

Strawberry Clown

Strawberry Clown's profile picture

I love u!!<33


Report Comment

Pineie / Charlie ๋࣭ ⭑

Pineie / Charlie ๋࣭ ⭑💻's profile picture

oh my god thank you so much 🙏 I’ve been struggling to make my whole profile space mono and this helped so much omg. will try tomorrow (about to head to bed now lolz)


Report Comment

Freaky ruu

Freaky ruu's profile picture

It doesn't work, I'm confused


Report Comment



it isnt working for me either, did you manage to figure it out?

by shiloh / charlea 🪲; ; Report

Chinchilla ⟡ - [autoplay]

Chinchilla ⟡ - [autoplay]'s profile picture

the font i want isn't on google fonts. does anyone know if you can use dafont?


Report Comment

orble

orble's profile picture

I'm so confused


Report Comment

mai

mai's profile picture

How can i change the color and font size, i saw a reply with a code how to make ur font bigger but it just isnt working for me.


Report Comment



did you figure it out? im having the same problem

by adrina ! !; ; Report

did you figure it out? im having the same problem

by adrina ! !; ; Report