What is the first step to use a custom font in Tailwind CSS?
You need to import the custom font files (like .woff or .ttf) into your project and define them in your CSS using <code>@font-face</code>.
Click to reveal answer
beginner
How do you add a custom font family to Tailwind's configuration?
In tailwind.config.js, extend the theme.fontFamily object by adding your custom font name and fallback fonts.
Click to reveal answer
beginner
Why should you include fallback fonts when defining a custom font in Tailwind?
Fallback fonts ensure text is still readable if the custom font fails to load or is unsupported on some devices.
Click to reveal answer
beginner
How do you apply your custom font to an element using Tailwind classes?
Use the class name you defined in <code>tailwind.config.js</code> for your font family, for example <code>class="font-customName"</code>.
Click to reveal answer
intermediate
What is a good practice to ensure your custom font works well on different screen sizes?
Use responsive design with Tailwind’s utility classes and test font appearance on various devices to maintain readability.
Click to reveal answer
Which file do you modify to add a custom font family in Tailwind CSS?
Atailwind.config.js
Bindex.html
Cpackage.json
Dpostcss.config.js
✗ Incorrect
The tailwind.config.js file is where you extend Tailwind's theme settings, including fonts.
What CSS rule is used to load a custom font file?
A@import-font
B@font-load
C@font-face
D@font-style
✗ Incorrect
The @font-face rule defines custom fonts by linking font files to font-family names.
Why include fallback fonts when defining a custom font?
ATo add animations
BTo improve loading speed
CTo reduce file size
DTo ensure text displays if custom font fails
✗ Incorrect
Fallback fonts ensure text remains readable if the custom font cannot load.
How do you apply a custom font named 'myFont' in Tailwind CSS classes?
Aclass="font-family-myFont"
Bclass="font-myFont"
Cclass="myFont"
Dclass="text-myFont"
✗ Incorrect
Tailwind uses the prefix font- followed by the font name to apply font families.
Which unit is recommended for font sizes in Tailwind for better accessibility?
Arem
Bpt
Cpx
Dcm
✗ Incorrect
Using rem units scales fonts relative to the root size, improving accessibility and responsiveness.
Explain the steps to add and use a custom font in a Tailwind CSS project.
Think about loading the font, telling Tailwind about it, then using it.
You got /3 concepts.
Why is it important to include fallback fonts and test your custom font on different devices?
Consider what happens if the font doesn’t load or looks different.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using @font-face in Tailwind CSS when integrating a custom font?
easy
A. To load and define a custom font so it can be used in your styles
B. To create animations for text using the font
C. To automatically download fonts from Google Fonts
D. To change the font size of text elements
Solution
Step 1: Understand the role of @font-face
@font-face is a CSS rule that lets you load a custom font file into your website.
Step 2: Connect @font-face to Tailwind usage
After loading the font with @font-face, you extend Tailwind's fontFamily to use that font in your classes.
Final Answer:
To load and define a custom font so it can be used in your styles -> Option A
Quick Check:
@font-face loads fonts = D [OK]
Hint: Remember: @font-face loads fonts, not styles [OK]
Common Mistakes:
Thinking @font-face changes font size
Confusing font loading with animations
Assuming it downloads fonts automatically
2. Which of the following is the correct way to extend Tailwind's fontFamily in tailwind.config.js to add a custom font named 'MyFont'?
easy
A. fontFamily: { myfont: 'MyFont' }
B. fontFamily: { 'MyFont': ['custom', 'sans-serif'] }
C. fontFamily: { custom: ['MyFont', 'sans-serif'] }
D. fontFamily: { custom: 'MyFont', fallback: 'sans-serif' }
Solution
Step 1: Recall Tailwind fontFamily syntax
Tailwind expects font families as arrays with font names and fallbacks, e.g., fontFamily: { key: ['FontName', 'fallback'] }.
Step 2: Match correct syntax
fontFamily: { custom: ['MyFont', 'sans-serif'] } correctly uses custom as key and an array with 'MyFont' and 'sans-serif'. Others misuse keys or values.
Final Answer:
fontFamily: { custom: ['MyFont', 'sans-serif'] } -> Option C
Quick Check:
fontFamily uses arrays for fonts = C [OK]
Hint: Use arrays for font names and fallbacks in config [OK]
Common Mistakes:
Using strings instead of arrays for fontFamily
Swapping keys and values
Missing fallback fonts
3. Given this Tailwind config extension:
fontFamily: { custom: ['MyFont', 'sans-serif'] }
and this HTML:
<p class="font-custom">Hello</p>
What font will the paragraph use if 'MyFont' is loaded correctly?
medium
A. No font, text will be invisible
B. The browser default font
C. 'sans-serif' fallback font only
D. 'MyFont' custom font
Solution
Step 1: Understand class usage
The class font-custom applies the font family named 'custom' from Tailwind config.
Step 2: Check font loading
If 'MyFont' is loaded correctly via @font-face, it will be used first, with 'sans-serif' as fallback.
Final Answer:
'MyFont' custom font -> Option D
Quick Check:
font-custom uses 'MyFont' if loaded = A [OK]
Hint: font-custom uses your custom font if loaded properly [OK]
But your text with font-custom class still shows default font. What is the likely mistake?
medium
A. You used the wrong font file format
B. You forgot to extend fontFamily in tailwind.config.js
C. You applied the wrong Tailwind class name
D. You did not include the font file in your HTML
Solution
Step 1: Check font-face usage
The font is loaded with @font-face, so the font file is available.
Step 2: Verify Tailwind config
Without extending fontFamily in tailwind.config.js, the class font-custom won't apply the new font.
Final Answer:
You forgot to extend fontFamily in tailwind.config.js -> Option B
Quick Check:
fontFamily extension missing = B [OK]
Hint: Always extend fontFamily to use custom fonts in Tailwind [OK]
Common Mistakes:
Not extending fontFamily in config
Using wrong class names
Forgetting to rebuild Tailwind after config change
5. You want to use two custom fonts, 'MyFontBold' and 'MyFontLight', in Tailwind. How should you configure tailwind.config.js and your CSS to use font-boldcustom and font-lightcustom classes for them?
hard
A. Define two @font-face rules with different font-family names and extend fontFamily with keys 'boldcustom' and 'lightcustom' pointing to those fonts
B. Use one @font-face with both fonts and extend fontFamily with a single key
C. Only extend fontFamily once and use CSS font-weight to switch fonts
D. Add both fonts in one @font-face and use font-custom class for both
Solution
Step 1: Define separate @font-face rules
Each font variant needs its own @font-face with unique font-family names like 'MyFontBold' and 'MyFontLight'.
Step 2: Extend Tailwind's fontFamily
In tailwind.config.js, add keys 'boldcustom' and 'lightcustom' pointing to these font-family names so you can use font-boldcustom and font-lightcustom classes.
Final Answer:
Define two @font-face rules and extend fontFamily with 'boldcustom' and 'lightcustom' -> Option A
Quick Check:
Separate font-faces + fontFamily keys = A [OK]
Hint: Use separate font-family names and keys for each font variant [OK]
Common Mistakes:
Trying to combine fonts in one @font-face
Using CSS font-weight instead of separate font-family
Not extending fontFamily for each font variant
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.