An example site using custom fonts.
- Create a
static
directory at the root of your site. - Place your font files and a
fonts.css
file in thestatic
directory.
static
└── fonts
├── fonts.css
└── Rounded_Elegance.woff
/* static/fonts/fonts.css */
@font-face {
font-family: "Rounded";
src: url("Rounded_Elegance.woff") format("woff");
}
- Install
gatsby-plugin-web-font-loader
and configure it as follows ingatsby-config.js
require(`dotenv`).config();
module.exports = {
siteMetadata: {
title: "Reflex",
description: "Starter for Reflex.",
siteUrl: process.env.SITE_URL || "http://localhost:8000",
},
plugins: [
"@reflexjs/gatsby-theme-base",
{
resolve: "gatsby-plugin-web-font-loader",
options: {
custom: {
families: ["Rounded"],
urls: ["fonts/fonts.css"],
},
},
},
],
};
- Import your custom
fonts.css
ingatsby-browser.js
// gatsby-browser.js
import "./static/fonts/fonts.css";
- Create
src/@reflexjs/gatsby-theme-base/theme.js
and add the font for your heading or body.
// src/@reflexjs/gatsby-theme-base/theme.js
import base from "@reflexjs/preset-base";
export default {
preset: base,
fonts: {
heading: "Rounded",
},
};