0
0
NextJSframework~20 mins

Font optimization with next/font in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Font Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered font style when using next/font with Google Fonts?

Consider this Next.js component using next/font/google to load the Roboto font:

import { Roboto } from 'next/font/google';

const roboto = Roboto({ subsets: ['latin'], weight: '400' });

export default function Home() {
  return <main className={roboto.className}>Hello World</main>;
}

What font style will the text inside <main> have?

NextJS
import { Roboto } from 'next/font/google';

const roboto = Roboto({ subsets: ['latin'], weight: '400' });

export default function Home() {
  return <main className={roboto.className}>Hello World</main>;
}
AThe text will use Roboto but with bold weight because weight '400' is ignored.
BThe text will use the default system font because next/font/google does not load fonts automatically.
CThe text will use the Roboto font with normal weight and latin subset loaded.
DThe text will not render because the className is undefined.
Attempts:
2 left
💡 Hint

Check how the Roboto function from next/font/google is used and what the className property does.

📝 Syntax
intermediate
2:00remaining
Which next/font/google import syntax is correct for loading multiple weights?

You want to load the Inter font with weights 400 and 700 using next/font/google. Which import and usage syntax is correct?

A
import { Inter } from 'next/font/google';
const inter = Inter({ weight: ['400', '700'], subsets: ['latin'] });
B
import Inter from 'next/font/google';
const inter = Inter({ weight: '400,700', subsets: ['latin'] });
C
import { Inter } from 'next/font/google';
const inter = Inter({ weights: ['400', '700'], subsets: ['latin'] });
D
import { Inter } from 'next/font/google';
const inter = Inter({ weight: 400 || 700, subsets: ['latin'] });
Attempts:
2 left
💡 Hint

Check the property name and value type for specifying multiple weights in the font options.

🔧 Debug
advanced
2:00remaining
Why does this next/font/local font fail to apply styles?

Given this code snippet using next/font/local:

import localFont from 'next/font/local';

const myFont = localFont({
  src: './fonts/MyFont.woff2',
  weight: '400',
  style: 'normal'
});

export default function Page() {
  return <div className={myFont.className}>Test Text</div>;
}

The font styles do not apply in the browser. What is the most likely cause?

NextJS
import localFont from 'next/font/local';

const myFont = localFont({
  src: './fonts/MyFont.woff2',
  weight: '400',
  style: 'normal'
});

export default function Page() {
  return <div className={myFont.className}>Test Text</div>;
}
AThe className property is not available on the object returned by localFont.
BThe weight property must be a number, not a string.
CThe localFont function requires an array for the src property, not a string.
DThe relative path './fonts/MyFont.woff2' is incorrect or the file is missing.
Attempts:
2 left
💡 Hint

Check the file path and existence of the font file relative to the component.

state_output
advanced
2:00remaining
What is the effect of using next/font with variable fonts on page size?

You use a variable font with next/font/google like this:

import { Roboto_Flex } from 'next/font/google';

const robotoFlex = Roboto_Flex({ subsets: ['latin'] });

export default function Home() {
  return <main className={robotoFlex.className}>Hello</main>;
}

What is the expected effect on the page size and font loading compared to loading multiple static weights?

NextJS
import { Roboto_Flex } from 'next/font/google';

const robotoFlex = Roboto_Flex({ subsets: ['latin'] });

export default function Home() {
  return <main className={robotoFlex.className}>Hello</main>;
}
AThe page size is larger because variable fonts include all weights and styles by default.
BThe page size is smaller because the variable font loads once and covers many weights and styles.
CThe page size is the same as loading a single static weight font.
DThe font does not load because variable fonts are not supported by next/font.
Attempts:
2 left
💡 Hint

Think about how variable fonts bundle multiple styles in one file.

🧠 Conceptual
expert
3:00remaining
How does next/font optimize font loading for accessibility and performance?

Which of the following best describes how next/font improves font loading in Next.js apps?

AIt automatically inlines critical font CSS, preloads fonts, and avoids layout shifts by applying font classes at build time.
BIt loads fonts only on user interaction to reduce initial load time but may cause layout shifts.
CIt bundles all font files into JavaScript to reduce HTTP requests but increases JS size.
DIt disables font loading on slow connections to improve accessibility.
Attempts:
2 left
💡 Hint

Consider how next/font handles font CSS and rendering to improve user experience.