Font optimization in Next.js means loading fonts in a way that makes pages load faster and look good quickly. It automatically preloads and subsets fonts to reduce the size and improve performance.
Click to reveal answer
beginner
Why should you self-host fonts instead of using third-party font providers?
Self-hosting fonts means storing font files on your own server. This improves privacy, reduces external requests, and gives you full control over font loading and caching.
Click to reveal answer
intermediate
How do you add a Google font with optimization in Next.js?
You can import fonts from 'next/font/google' and use them as React components. Next.js will automatically optimize and preload these fonts for you.
Click to reveal answer
intermediate
What is the benefit of font subsetting?
Font subsetting means including only the characters you need from a font. This reduces file size and speeds up page loading.
Click to reveal answer
intermediate
How can you self-host custom fonts in a Next.js project?
Place font files in the public folder, then use CSS @font-face rules to load them. This lets you control font loading without relying on external services.
Click to reveal answer
What does Next.js do automatically when you import fonts from 'next/font/google'?
AUploads fonts to a third-party server
BPreloads and subsets fonts for better performance
CConverts fonts to images
DDisables font loading
✗ Incorrect
Next.js preloads and subsets fonts imported from 'next/font/google' to improve loading speed and reduce font size.
Why is self-hosting fonts better for privacy?
ABecause it avoids sending user data to external font servers
BBecause it encrypts fonts automatically
CBecause it hides fonts from the browser
DBecause it disables fonts
✗ Incorrect
Self-hosting fonts avoids requests to external servers, which can track user data, thus improving privacy.
Where should you place font files to self-host them in a Next.js project?
AIn the node_modules folder
BIn the styles folder only
CIn the pages folder
DIn the public folder
✗ Incorrect
The public folder is used to serve static assets like fonts directly in Next.js.
What is font subsetting?
AIncluding only needed characters in a font file
BChanging font colors
CConverting fonts to SVG
DUsing multiple fonts at once
✗ Incorrect
Font subsetting reduces font file size by including only the characters you need.
Which of these is NOT a benefit of font optimization?
AFaster page load times
BReduced font file size
CAutomatic font color changes
DBetter user experience
✗ Incorrect
Font optimization improves loading and size but does not change font colors automatically.
Explain how Next.js helps with font optimization when using Google Fonts.
Think about how Next.js handles font files behind the scenes.
You got /4 concepts.
Describe the steps to self-host a custom font in a Next.js project.
Consider where static files go and how CSS loads fonts.
You got /4 concepts.
Practice
(1/5)
1. What is the main benefit of self-hosting fonts in a Next.js application?
easy
A. Allows fonts to be loaded only on mobile devices
B. Automatically converts fonts to SVG format
C. Improves website speed and user privacy by serving fonts locally
D. Enables fonts to be downloaded from Google Fonts CDN
Solution
Step 1: Understand what self-hosting means
Self-hosting fonts means serving font files from your own server instead of external sources.
Step 2: Identify benefits of self-hosting in Next.js
This improves loading speed because fonts are fetched faster and enhances privacy by not contacting third-party servers.
Final Answer:
Improves website speed and user privacy by serving fonts locally -> Option C
Quick Check:
Self-hosting = faster load + privacy [OK]
Hint: Self-hosting means local font files, boosting speed and privacy [OK]
Common Mistakes:
Thinking self-hosting converts font formats automatically
Believing fonts load only on mobile devices
Confusing self-hosting with using external CDNs
2. Which is the correct way to import a local font using Next.js 14+ syntax?
easy
A. import localFont from 'next/font/google';
B. import { localFont } from 'next/font/google';
C. import { localFont } from 'next/font/local';
D. import localFont from 'next/font/local';
Solution
Step 1: Recall Next.js font import syntax
Local fonts are imported from 'next/font/local' as a default import.
Step 2: Check option correctness
import localFont from 'next/font/local'; uses default import from 'next/font/local', which is correct. Options A, B, and D incorrectly use 'google' path or named imports.
Final Answer:
import localFont from 'next/font/local'; -> Option D
Quick Check:
Local fonts use default import from 'next/font/local' [OK]
Hint: Local fonts import default from 'next/font/local' [OK]
Common Mistakes:
Using named imports instead of default import
Importing local fonts from 'next/font/google'
Confusing Google fonts import with local fonts
3. Given this code snippet in Next.js, what will be the font-family applied to the <main> element?
A. The fontFamily style should use 'var(--font)' instead of '--font'
B. The src path must be an absolute URL, not relative
C. localFont does not support .ttf files, only .woff2
D. className should be applied to <main>, not <div>
Solution
Step 1: Check fontFamily style syntax
CSS variables must be used with var(), so fontFamily should be 'var(--font)', not '--font'.
Step 2: Verify other parts
The src path can be relative, .ttf is supported, and className can be on any element.
Final Answer:
The fontFamily style should use 'var(--font)' instead of '--font' -> Option A
Quick Check:
CSS variable usage requires var() [OK]
Hint: Use var(--variable) syntax for CSS variables in style [OK]
Common Mistakes:
Omitting var() around CSS variable in style
Thinking relative paths are invalid
Assuming .ttf fonts are unsupported
5. You want to optimize font loading in a Next.js 14 app by self-hosting multiple font weights of 'OpenSans'. Which approach correctly applies different weights using next/font/local and CSS variables?
hard
A. Load all font files manually in _app.js without using next/font/local
B. Configure a single localFont with src as an array specifying path and weight for each file, assign a single CSS variable
C. Use next/font/google for all weights and ignore local hosting
D. Import only one font weight and use CSS font-weight property to simulate others
Solution
Step 1: Understand multiple font weights with localFont
Multiple weights are handled in one localFont call using src: [{ path: './OpenSans-Regular.woff2', weight: '400' }, { path: './OpenSans-Bold.woff2', weight: '700' }], with a single CSS variable like '--font-opensans'.
Step 2: Combine variables in CSS or className for usage
Apply the font className or variable to an ancestor element, then use font-family: var(--font-opensans) with font-weight in styles.
Step 3: Evaluate other options
Import only one font weight and use CSS font-weight property to simulate others is incorrect because CSS font-weight cannot simulate different font files. Use next/font/google for all weights and ignore local hosting ignores self-hosting. Load all font files manually in _app.js without using next/font/local is manual and not optimized.
Final Answer:
Configure a single localFont with src as an array specifying path and weight for each file, assign a single CSS variable -> Option B
Quick Check:
src array + single variable = correct multi-weight self-hosting [OK]
Hint: Single localFont src array for weights + shared CSS variable [OK]
Common Mistakes:
Trying to fake font weights with CSS alone
Using Google fonts instead of self-hosting
Manually loading fonts without next/font/local benefits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.