Frontendroom
Tools
Categories
ShortsAbout
Posted on: February 19, 2023|Amrish Kushwaha

How to add google fonts as local fonts

How to add google fonts as local fonts
  1. x
    1. Now Playing
      Up NextHow to Download Creative Fabrica Font and Upload it to Canva
    2. Now Playing
      Up NextHow to Add New Fonts to Microsoft Word
    3. Now Playing
      Up NextHow to Change Font Size VODAFONE Smart 4 max – Font Size & Style
    4. Now Playing
      Up NextHow to Change Font Size in Google Docs for an Entire Document
    5. Now Playing
      Up NextHow to Change Font Style in VIVO X60 – Customize Font
    6. Now Playing
      Up NextHow to Change Font Size in GOOGLE Pixel 5 – Adjust Font Size
    7. Now Playing
      Up NextHow to Change Default Paragraph Font in Google Docs‍
    8. Now Playing
      Up NextHow to Change the Font on All Slides in Google Slides
    9. Now Playing
      Up NextHow to Change Font Style in INFINIX Hot 12i – Font Look
    10. Now Playing
      Up NextHow to Manage Font on Samsung Galaxy A23 - Choose The Best Font Style
    11. Now Playing
      Up NextHow to Change Font Style on Samsung Galaxy S4 – Customize Font Style
    12. Now Playing
      Up NextHow to Change Font Size in SAMSUNG Galaxy Note10+
    13. Now Playing
      Up NextHow to Install Font in SAMSUNG Galaxy A14 - Download Rosemary Font
    14. Now Playing
      Up NextHow to Change Font Style on SAMSUNG Galaxy S24 Ultra
    15. Now Playing
      Up NextHow to Change Font Style in INFINIX S5 – Adjust Font Type
    16. Now Playing
      Up NextHow to Change Style of Font in Google Pixel 4A – Pick Different Font Style
    17. Now Playing
      Up NextHow to Change Font Size in GOOGLE Pixel 7 - Font Settings
    18. Now Playing
      Up NextHow to Change Font Style in POCO X5 – Font Style Option
    19. Now Playing
      Up NextHow to Change Font on Instagram - Change Font Style
    20. Now Playing
      Up NextWhat Font is That Website Using? Tools to Find Out Instantly
x

One of the simple requirements of the web developer to add custom fonts on the website. Some times we want to add google fonts as local fonts to save our bandwidth, to save the numbers of network calls on our website.

Steps to add google fonts as local fonts

  1. Go to Google webfonts helper
  2. Select your intended fonts and its styles.
  3. Download the fonts zip file
  4. Copy CSS to right place - I mean in right css file and use the fonts.

Go to Google webfonts helper

If you download fonts from google fonts https://fonts.google.com/, it will only give ttf files. For the best support of the font in various devices and browser, you need a lot more types of fonts such as woff, woff2, eot, svg. Google webfonts helper is the website which provides the various versions of the same fonts so that that font can be best supported in all the browsers.

Select your intended fonts and its styles:

Now search your intended font, select charset and font styles for this particular font.

Download the fonts zip file:

Now download the font zip file to use it locally.

Copy CSS to right place:

Google webfonts helper also provides css to use the fonts locally. One of the good feature of the google webfonts helper is that you can set font path prefixes relative to fonts folder where all fonts files are.

That's all. Since you got font files and CSS to use that font, you are good to use it on your website or web app.

Example: How to add google fonts as local fonts in gatsby website:

Let's say you want to add Titillium Web font in your gatsby website

  1. Follow first 2 steps - https://google-webfonts-helper.herokuapp.com/fonts/titillium-web?subsets=latin.

  2. Now download the font zip file, extract the folder, copy all files from the extracted folder and paste it under src/fonts/titillium-web-v8-latin.

  3. Create fonts.css file in fonts page and paste CSS from Google Webfonts helper. Note - Before copying CSS, set the path prefix to /titillium-web-v8-latin/.

/* '/src/fonts/fonts.css' */
/* titillium-web-200 - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 200;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-200.eot"); /* IE9 Compat Modes */
src: local("Titillium Web ExtraLight"), local("TitilliumWeb-ExtraLight"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-200.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-200.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-200.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-200.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-200.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
/* titillium-web-300 - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 300;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-300.eot"); /* IE9 Compat Modes */
src: local("Titillium Web Light"), local("TitilliumWeb-Light"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-300.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-300.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-300.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-300.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-300.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
/* titillium-web-regular - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 400;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.eot"); /* IE9 Compat Modes */
src: local("Titillium Web Regular"), local("TitilliumWeb-Regular"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.eot?#iefix")
format("embedded-opentype"), /* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-regular.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
/* titillium-web-600 - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 600;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-600.eot"); /* IE9 Compat Modes */
src: local("Titillium Web SemiBold"), local("TitilliumWeb-SemiBold"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-600.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-600.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-600.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-600.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-600.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
/* titillium-web-700 - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 700;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-700.eot"); /* IE9 Compat Modes */
src: local("Titillium Web Bold"), local("TitilliumWeb-Bold"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-700.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-700.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-700.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-700.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-700.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
/* titillium-web-900 - latin */
@font-face {
font-family: "Titillium Web";
font-style: normal;
font-weight: 900;
src: url("/titillium-web-v8-latin/titillium-web-v8-latin-900.eot"); /* IE9 Compat Modes */
src: local("Titillium Web Black"), local("TitilliumWeb-Black"),
url("/titillium-web-v8-latin/titillium-web-v8-latin-900.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("/titillium-web-v8-latin/titillium-web-v8-latin-900.woff2") format("woff2"),
/* Super Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-900.woff") format("woff"),
/* Modern Browsers */
url("/titillium-web-v8-latin/titillium-web-v8-latin-900.ttf") format("truetype"),
/* Safari, Android, iOS */
url("/titillium-web-v8-latin/titillium-web-v8-latin-900.svg#TitilliumWeb")
format("svg"); /* Legacy iOS */
}
  1. Now include fonts.css in root component of your gatsby and use it.
body {
font-family: "Titillium Web", sans-serif;
}

That's all

I hope that you like the article.

Keep coding and keep learning...

About author:

Amrish Kushwaha

Amrish Kushwaha

I am Amrish Kushwaha. Software Engineer, Maker, Writer. I am currently focused on frontend development with curiosity of building end to end software system. Currently I am working at Rafay Systems. I love to write as well as build side projects when I am free.

Related category articles:

How to add 3rd party script in your gatsby website

How to add 3rd party script in your gatsby website

Read
X
Current Time 0:00
Duration 0:00
Remaining Time 0:00
1x
    • captions off, selected