Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Enhancing the Design With CSS Web Fonts with @font-face

Stefan Cutajar
Stefan Cutajar
7,747 Points

Downloaded web fonts

Hi, I'm trying to add some fonts to a web page and would like to add some fonts that I downloaded how can I do that please?

1 Answer

Matthew Long
Matthew Long
28,407 Points

You're off to a good start knowing you should use @font-face! The basic syntax is:

@font-face {
  font-family: 'name-you-give-your-font';
  src: url(/path-to-your-font/font.otf);
}

Now to use this font on your site, you use font-family:

body {
  font-family: 'name-you-give-your-font', sans-serif;
}

Note, I put it on the body element, but you can use it wherever best fits your project. Also, it's a good idea to have a fallback font. In the example above the fallback font is sans-serif.

Hopefully this clears things up for you!

Stefan Cutajar
Stefan Cutajar
7,747 Points

Thanks I've managed :) was a bit confused since the fonts are on my computer not on the net.

Hey Matthew, I see you are using an .otf file. Guil doesn't mark this file. Is it appropiate to use this or should we only use eot's, woff's and ttf's as in the video?

Matthew Long
Matthew Long
28,407 Points

Technically you can use whatever gets the job done. But probably a good idea to stick with a format Guil recommends if possible.