4

I have recently been trying to embed font to my website. I don't get it to work, i have watched and read tutorials. I wan't to embed a font called "Ubuntu Light" in ttf format. This is what i have been trying:

#logBtn{
  font-family: 'UbuntuLight';
}
@font-face{
font-family: "UbuntuLight";
src: url("CSS/Ubuntu-L.ttf");
}

And the file in the folder: Treeview of project

I'm almost new to this, i've been coding HTML and CSS in maybe 4 months now. I have been stuck at this before, and that made me cancel my project, because i gave up. But i don't want to give up again. So i would really appreciate some help! :)

2
  • I really recommend using google.com/fonts This includes the font you currently need and thousands of others, I've not looked but it it because you're importing the font AFTER it being used? - Also try removing the single-apostrophe Commented May 12, 2016 at 19:31
  • Did you convert the font via a webfont generator such as fontsquirrel.com/tools/webfont-generator before adding it to your project? Commented May 12, 2016 at 19:37

2 Answers 2

4

You can embed a font quick and easy by using this code:

@font-face {
  font-family: 'Name';
  src: url('Font.ext');
  font-weight: 400;
  font-style: normal;
}

Where Font.ext should be replaced with your font file and its extention (file type) e.g.

src: url('Ubuntu-L.ttf');

And the following font-weight and font-style should be referencing the specific font choice.

Sign up to request clarification or add additional context in comments.

2 Comments

But, it does not work. Could you please see what i have done wrong? This is the code: #logBtn{ font-family: "UbuntuL"; font-size: 30px; color: white; } @font-face { font-family: 'UbuntuL'; src: url('UbuntuL.ttf'); font-weight: 400; font-style: Light; } Maybe easier to see here: i.gyazo.com/f1d365053f57ade7476bb886b1f34b86.png
Your font-face declaration should always be at the top of your CSS file, @SynomousArtz
0

The url(...) path is relative to the stylesheet.

Therefore, because your stylesheet is in the CSS folder you don't need to include that in the url:

@font-face{
  font-family: "UbuntuLight";
  src: url("Ubuntu-L.ttf");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.