Skip to content
✏️ Font selector component for Google Fonts
TypeScript JavaScript CSS
Branch: master
Clone or download

Latest commit

Latest commit 0d7e819 May 13, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add GitHub Actions workflows Apr 23, 2020
.storybook Update dependencies Apr 23, 2020
src Initialize font manager after component mount May 13, 2020
stories Update dependencies Apr 23, 2020
.editorconfig Fix editorconfig Aug 10, 2018
.gitattributes Add .gitattributes Feb 8, 2019
.gitignore Rewrite library Mar 29, 2019
LICENSE Initial commit Jan 26, 2018 Update dependencies Apr 23, 2020
package.json v3.5.2 May 13, 2020
rollup.config.js Update dependencies Oct 5, 2019
tsconfig.json Process Typescript with Babel Aug 5, 2019
yarn.lock Update dependencies Apr 23, 2020

Font Picker for React

A simple, customizable font picker allowing users to preview, select and use Google Fonts on your website.

  • Simple setup
  • No dependencies
  • Automatic font download and generation of the required CSS selectors
  • Efficient font previews (full fonts are only downloaded on selection)


This is the React component for the Font Picker library.

Font picker demo

Getting started

To be able to access the API, you'll need to generate a Google Fonts API key.

1. Setup

Install the font-picker-react package using NPM:

npm install font-picker-react

2. Displaying the font picker

Add the FontPicker component to your React code:

import React, { Component } from "react";
import FontPicker from "font-picker-react";

export default class ExampleComponent extends Component {
	constructor(props) {
		this.state = {
			activeFontFamily: "Open Sans",

	render() {
		return (
					onChange={(nextFont) =>
				<p className="apply-font">The font will be applied to this text.</p>

3. Applying the selected font

Add the class "apply-font" to all JSX elements you want to apply the selected font to.

When the user selects a font, it will automatically be downloaded and applied to all elements with the "apply-font" class.


The following props can be passed to the FontPicker component:

  • apiKey (required): Google API key
  • activeFontFamily: Font that should be selected in the font picker and applied to the text. Should be stored in the component state and updated using onChange
  • onChange: Function which is executed when the user changes the active font. This function should update activeFontFamily in the component state
  • pickerId: If you have multiple font pickers on your site, you need to give them unique IDs which must be provided as a prop and appended to the .apply-font class names. Example: If pickerId="main", use className="apply-font-main"
  • families: If only specific fonts shall appear in the list, specify their names in an array. Default: All font families
  • categories: Array of font categories to include in the list. Possible values: "sans-serif", "serif", "display", "handwriting", "monospace". Default: All categories
  • scripts: Array of scripts which the fonts must include and which will be downloaded on font selection. Default: ["latin"]. Example: ["latin", "greek", "hebrew"] (see all possible values)
  • variants: Array of variants which the fonts must include and which will be downloaded on font selection. Default: ["regular"]. Example: ["regular", "italic", "700", "700italic"] (see all possible values)
  • filter: Function which must evaluate to true for a font to be included in the list. Default: font => true. Example: If font =>"m"), only fonts whose names begin with "M" will be in the list
  • limit: Maximum number of fonts to display in the list (the least popular fonts will be omitted). Default: 50
  • sort: Sorting attribute for the font list. Possible values: "alphabet", "popularity". Default: "alphabet"

Currently, only the activeFontFamily, onChange and sort props are reactive.


Requirements: Node.js, Yarn

  1. Clone this repository: git clone REPO_URL
  2. Install all dependencies: yarn
  3. Generate the library bundle: yarn start
  4. View the rendered component on localhost:3000

Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.

You can’t perform that action at this time.