Reputation: 91
I need to include new font family in my angular 6 project
@import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
import the google font in my scss file but it doesn't work well
Upvotes: 0
Views: 5462
Reputation: 2920
There are two main ways of adding fonts in angular:
npm install roboto-fontface --save
"styles": [
"styles.css",
"../node_modules/roboto-fontface/css/roboto/roboto-fontface.css"
],
@import url('https://fonts.googleapis.com/css?family=Roboto');
and then use it in you scss file as Roboto.
However, using CDN might cause some problems as Angular treats this as low priority and some browsers might fail to load the font. In that case the safest way is to go with the first way of doing it. Here is an article that explains further this issue and the comparison of CDN and hosting the fonts yourselve
Upvotes: 1
Reputation: 91
Step #1
Create a scss file with font face and place it somewhere, like in assets/fonts
font_name.scss
@font-face
{
font-family: Futura Bk Bt;
src: url("./FuturaBookfont.woff") format("woff");
}
woff file converter link https://www.font-converter.net/en
Step #2
Paste the .woff file into the src url path.
Step #3
Include the scss file into your angular.json file
{
...
"projects": {
"project-name": {
...
"architect": {
"build": {
...
"options": {
...
"styles": [
...
"src/assets/fonts/font_name.scss",
...
],
...
},
...
},
...,
"test": {
...
"options": {
...
"styles": [
...
"src/assets/fonts/font_name.scss",
...
],
...
}
},
...
}
},
}
It is Also Used For All Fonts Include Paid Fonts Also(Ex: Futura Bk Bt,..)
Upvotes: 0
Reputation: 1
Try to import in index.html
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
Upvotes: 0