Skip to content
Simple But How

How to Add a Google Font to Your Website

Three ways to use a Google Font on a website, with copy-and-paste code, and how to keep the page fast and private.

Published · How we check our guides

There are two approaches: let Google serve the font files, or host them on your own site. Linking from Google is quicker to set up. Hosting them yourself keeps visitor data on your site and gives you more control over speed.

The examples below use Inter. Every font page in our library has the same code ready for that font.

Add these lines inside the <head> of your page:

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">

Then use the font in your CSS:

body {
  font-family: "Inter", system-ui, sans-serif;
}

How to read the link:

  • family=Inter is the font name. Replace spaces with +, as in Playfair+Display.
  • wght@400;700 lists the weights to load, in ascending order. Only ask for weights you use.
  • display=swap shows text in a fallback font straight away and swaps when the web font arrives.

To load two families, repeat the family= part: family=Inter:wght@400;700&family=Lora:wght@600.

Option 2: host the font yourself with npm

If your site has a build step, the Fontsource packages put the font files in your own bundle:

npm install @fontsource/inter

Import it once, in your main JavaScript or CSS entry file:

import "@fontsource/inter/400.css";
import "@fontsource/inter/700.css";

Then set font-family: "Inter", system-ui, sans-serif; as before. The files are served from your own domain, so the browser makes no request to Google.

Option 3: host the files by hand

  1. Download the family and keep the .woff2 files, which are the smallest format and work in every current browser.
  2. Upload them to your site, for example in a /fonts/ folder.
  3. Declare each one in your CSS:
@font-face {
  font-family: "Inter";
  src: url("/fonts/inter-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

Add one @font-face block per weight and style, changing the file name and font-weight.

Keep it fast

  • Load fewer files. Each weight and each italic is a separate download. Regular and bold are enough for most sites.
  • Use a variable font when you need three or more weights. One file covers the whole range.
  • Always include fallbacks. End every font-family with system fonts and a generic family. The font stack generator builds a matching list.
  • Preload only the main text font, and only if you host it yourself:
<link rel="preload" href="/fonts/inter-400.woff2" as="font" type="font/woff2" crossorigin>

Privacy

When a page links to Google Fonts, each visitor’s browser contacts Google’s servers, which reveals their IP address to Google. Some European courts and regulators have treated that as a transfer of personal data that needs consent. If your site has visitors in the EU, hosting the font files yourself (option 2 or 3) avoids the question.

If the font does not show

  • Check the spelling and capital letters of the family name in your CSS. It must match exactly.
  • Make sure the weight you set in CSS is one you loaded. Asking for font-weight: 600 when only 400 and 700 are loaded gives a faked or substituted weight.
  • Open the browser’s developer tools, look at the Network tab and reload. A font file with a 404 status means the path is wrong.

Next steps