Skip to content

Instantly share code, notes, and snippets.

@dnnysng
Last active November 20, 2022 11:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnysng/5bc61b2b85dd01ec1809367038b41bb0 to your computer and use it in GitHub Desktop.
Save dnnysng/5bc61b2b85dd01ec1809367038b41bb0 to your computer and use it in GitHub Desktop.
Importing a Font to a React Project
/* FONT_NAME = Your font name, i.e. Arial */
/* PATH_TO_YOUR_FILE = The relative path to your font from index.css */
/* Note: Most of the Google fonts I've seen are .ttf which is the 'truetype' format */
@font-face {
font-family: 'FONT_NAME';
src: local('FONT_NAME'),
url('PATH_TO_YOUR_FILE') format('truetype');
}
/* Optionally you may also set other variables such as 'font-weight' while importing */
/* In the example below the font will be used when you use a weight of '700' */
@font-face {
font-family: 'FONT_NAME';
src: local('FONT_NAME'),
url('PATH_TO_YOUR_FILE') format('truetype');
font-weight: 700;
}
/* This is how you use the font */
.selector {
 font-family: 'FONT_NAME';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment