Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
How to Add Custom Local Fonts in Next.js ?
Next article icon

How to Add Custom Local Fonts in Next.js ?

Last Updated : 23 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Adding custom fonts in Next.js project enhances the typography. It also improves the performance as the fonts are loaded directly from project assets.

They can be integrated by importing font files into a project, defining @font-face rules in CSS, and applying them across components for consistent styling and branding.

In this article, we will learn to add Custom Fonts to our Next.js project.

Approach

To add custom local font in Next js we will place the font files in public/fonts, define @font-face rules in fonts.css, import this CSS into your app, and apply font-family in components for cohesive branding and design consistency.

Steps to add Custom Fonts in Next.js

Step 1: Initialize Next App

Create a new next project using the command below. (Make sure you have npm and node installed)

npx create-next-app myproject

Step 2: Create fonts Directory

Open the project in your code editor, and create a new folder in the root directory called fonts.

Step 3: Arrange Required Fonts

If you already have the fonts, then skip this step. Download the required fonts from Google Fonts.

 

For this article, we are downloading Rubik font from google fonts. 

Step 4: Move font to the fonts directory

Now move all the fonts to the /fonts directory, so that we can add a relative path in our CSS to access these fonts.

Project Structure: 

 

Step 5: Integreate using CSS

Add CSS to create a custom font family for these fonts. We'll add this CSS in global styles so that the whole application can access these fonts, but you can also add fonts for a specific web page. 

CSS
/* /styles/global.css */  @font-face { 	font-family: 'Rubik'; 	src: url('../fonts/rubik/Rubik-Regular.ttf'); 	font-weight: normal; 	font-style: normal; }  @font-face { 	font-family: 'Rubik'; 	src: url('../fonts/rubik/Rubik-Bold.ttf'); 	font-weight: bold; 	font-style: normal; }  @font-face { 	font-family: 'Rubik'; 	src: url('../fonts/rubik/Rubik-Italic.ttf'); 	font-weight: normal; 	font-style: italic; } 

We can also add multiple font weights and font styles for the same font family as shown above.

Step 6: Test the added fonts

Let's test this font in our ./pages/index.js file (Home page). We'll remove all the boilerplate code for simplicity and add its styles to ./styles/Home.module.css .

CSS
/* styles/Home.module.css */  .testFont { 	font-family: 'Rubik', sans-serif; 	font-weight: bold; 	color: green; 	font-size: 3rem; } 
JavaScript
// pages/index.js  import styles from "../styles/Home.module.css";  export default function Home() {     return <h1 className={styles.testFont}>Hello Geeks</h1>; } 

Step to run the app: Use the below command to run the application

npm run dev

Output: 


Next Article
How to Add Custom Local Fonts in Next.js ?

K

ksangtiani13
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • Next.js
  • Next.js - Questions

Similar Reads

    How to Add Custom Fonts in VueJS ?
    Vue.js is a JavaScript framework used in building powerful and beautiful user interfaces. The key feature of Vue.js is its component-based architecture that allows the developers to create reusable and modular components. Custom fonts can bring uniqueness and visual appeal to your Vue.js application
    2 min read
    How to add ESLint in Next.js ?
    ESLint is a popular linting tool for identifying and fixing issues in JavaScript code. Adding ESLint to your Next.js project ensures that your code follows best practices and maintains a consistent style. This enhances code quality, helps catch errors early, and makes the codebase easier to maintain
    3 min read
    How to add CodeBlock in Next.js ?
    In this article, we are going to learn how we can add CodeBlock in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditiona
    2 min read
    How to add Calendar in Next.js ?
    Adding a calendar to a Next.js application enhances scheduling and event management. We can just install and use the available npm package. In this article, we are going to learn how we can add a calendar loader in NextJS.ApproachTo add our calendar we are going to use the react-calendar package. Th
    2 min read
    How To Add Font In CSS?
    Adding fonts to a website enhances its design and readability. In CSS, custom fonts can be applied using several techniques that allow web designers to include specific fonts that aren’t system defaults.PrerequisitesHTMLCSSThese are the approaches to add a font in CSS: Table of ContentUsing web-safe
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences