Home > Net >  Why is my font-family not working in css?
Why is my font-family not working in css?

Time:05-28

I can't seem to get any font to work. It was working originally, but I did something and now can't get it back. The error I get in JSFiddle is "Unexpected missing generic font family".

body {
  background-color: #ffffff;
  font-family: Aldhabi;
}

CodePudding user response:

You need to import it first to your css by using @import then you can use it.

@import url('http://fonts.cdnfonts.com/css/aldhabi');

body{
background-color: #ffffff;
font-family: 'Aldhabi', sans-serif;
}

CodePudding user response:

Whenever you want to use a new font-family, you have to import it from Google-fonts.

For example, if you want to import Poppins you have to include this line

`@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Pacifico&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Roboto Slab:wght@100;200;300;400;500;600;700;900&display=swap');` 

in the top of your CSS file.

And then use it where ever you want, Like this:

body{
  font-family: 'Poppins', sans-serif;
}
  • Related