VOOZH about

URL: https://blog.logrocket.com/add-custom-fonts-mui/

⇱ 3 ways to add custom fonts to your MUI project - LogRocket Blog


2022-11-15
1176
Linda Ikechukwu
25964
👁 Image

See how LogRocket's Galileo AI surfaces the most severe issues for you

No signup required

Check it out

Editor’s note: This article was last updated 15 November 2022 to reflect changes made in MUI v5, including removing the deprecated createMuiTheme function. 

👁 Add Custom Fonts MUI

With over 82k stars and 2,600 contributors on GitHub at the time of writing, MUI is one of the most loved UI component libraries for React developers. With its diverse set of commonly used UI components, developers can quickly and easily build web interfaces, focusing on functionality instead of UI implementation.

MUI uses principles from the material design guide created by Google. In this article, we’ll explore MUI and review three different ways to add custom fonts to your MUI project. Let’s get started!

🚀 Sign up for The Replay newsletter

The Replay is a weekly newsletter for dev and engineering leaders.

Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.

Getting started with MUI

This article assumes that you use Create React App or any of the other React toolchains. If you’re setting up your own toolchain and build pipeline, be sure to include a plugin or loader for loading fonts.

To get started, install Create React App as follows:

/ with npm
npx create-react-app font-app
//with yarn
yarn create-react-app font-app

To use MUI in your application, install it via npm or yarn:

// with npm
npm install @mui/material @emotion/react @emotion/styled

// with yarn
yarn add @mui/material @emotion/react @emotion/styled

Then, we’ll add some UI components to work within our App.js folder:

import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import './App.css';

function App() {
 return (
 <div className="App">
 <div>
 <Typography variant="h2" gutterBottom>
 Welcome to React
 &lt;/Typography>
 <Button variant="contained" color="secondary">Ready To Go</Button>
 </div>
 </div>
 );
}
export default App;

How to add custom fonts to your MUI project

Using your browser’s inspector to inspect the button and header, you’ll see that the UI components are rendered using the default font family of Roboto. So, how do we change that?

👁 Button Header Rendered Roboto Font
Roboto font

We’ll go through three different ways to add any font of your choice to your MUI project.

Method 1: Use the Google Fonts CDN

Head over to Google Fonts and select the font family of your choice; I’ll use the Chilanka Cursive font. Copy the CDN link and add it to the <head> of the public/index.html file as follows:

<link href="https://fonts.googleapis.com/css2?family=Chilanka&display=swap" rel="stylesheet">

To use the font, you’ll have to initialize it using CreateTheme, an API provided by MUI that generates a custom theme based on the options received, and ThemeProvider, a component used to inject custom themes into your application.

Add the code below to your App.js file:

import { createTheme, ThemeProvider } from '@mui/material';
const theme = createMuiTheme({
 typography: {
 fontFamily: [
 'Chilanka',
 'cursive',
 ].join(','),
 },});

Then, wrap your components with the default MUI ThemeProvider component, passing it theme props. The value of the theme props should be the name of your defined theme:

<ThemeProvider theme={theme}>
 <div className="App">
 <div>
 <Typography variant="h2" gutterBottom>
 Welcome to React
 </Typography>
 <Button variant="contained" color="secondary">Ready To Go</Button>
 </div>
 </div>
</ThemeProvider>

Inspecting the components now with the browser inspector tool, you’ll find that the font family has changed to Chilanka:

👁 React Components Rendered Chilanka
Welcome to React in Chilanka font

Method 2: Self host fonts using google-webfonts-helper

There are some benefits of self-hosting your fonts. It is significantly faster, and your fonts can load offline.

google-webfonts-helper is an amazing tool that makes self-hosting fonts hassle-free. It provides font files and font-face declarations based on the fonts, charsets, styles, and browser support you select.

Simply search for any Google Font and select the desired font weights. I’ll use Josefin Sans:

👁 Google Fonts List
List of Google Fonts

Copy the resulting font-face declarations into your src/index.css file. You can customize the font file location. The default assumes ../fonts/. We’ll use ./fonts because we’ll place the downloaded fonts in the src/fonts directory:

👁 Copy Font Face Declarations CSS File
Font sources

Finally, download your files. Unzip them and place them in your project in the appropriate location, src/fonts.

Like before, you’ll have to define the font family using CreateTheme and then wrap your components with the ThemeProvider component:

const theme = createTheme({
 typography: {
 fontFamily: [
 'Josefin Sans',
 'sans-serif',
 ].join(','),
},});

Inspecting now, you should see that the font family has changed to Josefin Sans:

👁 Font Family Changed ThemeProvider Component

Method 3: Self host fonts using the Typefaces npm packages

Typefaces is a collection of npm packages for Google Fonts as well as some other open source typefaces created by Kyle Matthews. Just like other dependencies, you can add a font to a project by installing it with npm. Using Typefaces is my favorite method because all website and web app dependencies should be managed through npm whenever possible.

Simply search through the repo for a typeface and click on the font folder to find the correct npm installation command. I’ll go with Cormorant:

npm install typeface-cormorant

Then, import the package into your project’s entry file, src/index.js in our case:

import "typeface-cormorant";

Like before, you’ll have to define your font family using CreateTheme and wrap your components with the Themeprovider component:

const theme = createTheme({
 typography: {
 fontFamily: [
 'Cormorant',
 'serif',
 ].join(','),
},});

Inspecting now, you’ll see that the font family has changed to Cormorant:

👁 Cormorant Font Themeprovider Component

Defining different fonts for different elements

What if you want to define different fonts for our header and button. Say, a primary font and a secondary font?

You’ll simply define two theme constants and wrap the intended components with the Themeprovider component, each with a theme prop of the corresponding font.

For example, if you want to use the Cormorant font for the heading and Josefin Sans for the button, you’ll first define two themes for the two fonts, respectively:

const headingFont = createTheme({
 typography: {
 fontFamily: [
 'Cormorant',
 'serif',
 ].join(','),
},});

const buttonFont = createTheme({
 typography: {
 fontFamily: [
 'Josefin Sans',
 'sans-serif',
 ].join(','),
},});

Then, wrap the target components with a ThemeProvider component of the required font, like below:

function App() {
 return (

 <div className="App">
 <div>
 <ThemeProvider theme={headingFont}>
 <Typography variant="h2" gutterBottom>
 Welcome to React
 </Typography>
 </ThemeProvider>
 <ThemeProvider theme={buttonFont}>
 <Button variant="contained" color="secondary">
 Ready To Go
 </Button>
 </ThemeProvider>

 </div>
 </div>
 );
}

Viola! You’ll see now that the heading is rendered with the Cormorant font and the button with the Josefin Sans font:

👁 Different Fonts Rendered React Components

👁 Welcome React Rendered MUI Font

Conclusion

In this article, we covered three simple ways to add custom fonts to a MUI project, including the Google Fonts CDN, google-webfonts-helper, and npm. We also looked at how to define separate fonts for different components. Be sure to leave a comment if you have any questions, happy coding!

Get set up with LogRocket's modern error tracking in minutes:

  1. Visit https://logrocket.com/signup/ to get an app ID
  2. Install LogRocket via npm or script tag. LogRocket.init() must be called client-side, not server-side

    $ npm i --save logrocket 
    
    // Code:
    
    import LogRocket from 'logrocket'; 
    LogRocket.init('app/id');
     
    // Add to your HTML:
    
    <script src="https://cdn.lr-ingest.com/LogRocket.min.js"></script>
    <script>window.LogRocket && window.LogRocket.init('app/id');</script>
     
  3. (Optional) Install plugins for deeper integrations with your stack:
    • Redux middleware
    • NgRx middleware
    • Vuex plugin
Get started now
👁 Image
👁 Image
👁 Image

Stop guessing about your digital experience with LogRocket

Get started for free

Recent posts:

Debug Next.js apps with AI agents and next-browser

Learn how next-browser gives AI agents runtime context for debugging Next.js apps, including React props, hydration, PPR, forms, and performance.

👁 Image
Emmanuel John
Jun 17, 2026 ⋅ 9 min read

Stop hardcoding LLM SDKs: Dynamic LLM routing with OpenRouter and Next.js

Build dynamic LLM routing in Next.js with OpenRouter, TanStack AI, task classification, model fallbacks, and cost-aware routing.

👁 Image
Chizaram Ken
Jun 16, 2026 ⋅ 13 min read

What is TSRX?: What JSX would look like if it were designed today

TSRX adds first-class control flow, conditional hooks, and scoped styles to React via a TypeScript compiler extension — no new framework required.

👁 Image
Ikeh Akinyemi
Jun 12, 2026 ⋅ 6 min read

How to add authentication to a React Native app with Better Auth

Learn how to build a full React Native auth system using Better Auth and Expo — with email/password login, Google OAuth, session persistence, and protected routes.

👁 Image
Chinwike Maduabuchi
Jun 9, 2026 ⋅ 13 min read
View all posts

Would you be interested in joining LogRocket's developer community?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now