📖 Scenario: You are building a simple webpage for a blog. The blog title and paragraph text should look good on all devices, from small phones to large desktop screens.
🎯 Goal: Create a responsive webpage using Tailwind CSS where the heading and paragraph text sizes adjust smoothly based on the screen size.
📋 What You'll Learn
Use Tailwind CSS utility classes for typography
Make the heading text scale responsively from small to large screens
Make the paragraph text scale responsively from small to large screens
Use semantic HTML elements
Ensure the page is accessible with proper language and meta tags
💡 Why This Matters
🌍 Real World
Responsive typography is essential for websites to look good and be readable on phones, tablets, and desktops. This skill helps create user-friendly websites.
💼 Career
Web developers often use Tailwind CSS to quickly build responsive designs. Knowing how to scale typography responsively is a common task in front-end development.
Progress0 / 4 steps
1
Create the basic HTML structure
Create a basic HTML5 skeleton with lang="en", charset="UTF-8", and a viewport meta tag. Inside the <body>, add a <main> element containing an <h1> with the text "Welcome to My Blog" and a <p> with the text "This is a sample paragraph to demonstrate responsive typography."
Tailwind
Hint
Start with a simple HTML page. Use <main> for the main content. Add the heading and paragraph inside it.
2
Add Tailwind CSS link and base typography classes
Add the Tailwind CSS CDN link inside the <head> section. Then, add Tailwind classes class="text-base p-4" to the <main> element to set base font size and padding.
Tailwind
Hint
Use the official Tailwind CDN link: https://cdn.tailwindcss.com. Add text-base and p-4 classes to <main>.
3
Make the heading text scale responsively
Add Tailwind classes to the <h1> element so that the font size is text-2xl on small screens, text-4xl on medium screens, and text-6xl on large screens.
Tailwind
Hint
Use Tailwind's responsive prefixes: md: for medium screens and lg: for large screens.
4
Make the paragraph text scale responsively
Add Tailwind classes to the <p> element so that the font size is text-sm on small screens, text-base on medium screens, and text-lg on large screens.
Tailwind
Hint
Use the same responsive prefixes for the paragraph text sizes as you did for the heading.
Practice
(1/5)
1. What does the Tailwind class text-lg md:text-xl do in terms of font size?
easy
A. Sets the font size to large on small screens and extra large on medium and bigger screens.
B. Sets the font size to extra large on all screen sizes.
C. Sets the font size to large only on medium screens.
D. Sets the font size to extra large only on small screens.
Solution
Step 1: Understand Tailwind responsive prefixes
The prefix md: applies styles starting from medium screen sizes (768px and up).
Step 2: Interpret the class text-lg md:text-xl
It sets font size to large by default, then changes to extra large on medium and larger screens.
Final Answer:
Sets the font size to large on small screens and extra large on medium and bigger screens. -> Option A
Quick Check:
Responsive prefix changes font size at medium breakpoint [OK]
Hint: Look for prefixes like md: to spot screen size changes [OK]
Common Mistakes:
Thinking md: applies to small screens
Assuming no change in font size
Confusing default and prefixed classes
2. Which of the following is the correct Tailwind syntax to make text size small on mobile and medium on large screens?
easy
A. text-md lg:text-sm
B. text-sm lg:text-md
C. text-sm lg:text-lg
D. text-lg md:text-sm
Solution
Step 1: Identify correct font size classes
Tailwind uses text-sm for small, text-md is not a valid class, text-lg is medium-large.
Step 2: Check responsive prefix usage
lg: applies styles at large screens (1024px+). So text-sm lg:text-lg means small text on mobile, larger text on large screens.
Final Answer:
text-sm lg:text-lg -> Option C
Quick Check:
Use valid classes and correct prefixes [OK]
Hint: Remember text-md is invalid; use text-sm, text-base, text-lg [OK]
Common Mistakes:
Using invalid class text-md
Reversing screen size prefixes
Mixing up font size names
3. What font size will the text have on a 1200px wide screen with this class: text-base sm:text-lg md:text-xl lg:text-2xl?
medium
A. text-base
B. text-xl
C. text-lg
D. text-2xl
Solution
Step 1: Identify screen size breakpoints
1200px width is larger than lg breakpoint (1024px), so lg: classes apply.
Step 2: Determine which font size applies
Since lg:text-2xl applies at 1024px+, the font size will be 2xl on 1200px screen.
Final Answer:
text-2xl -> Option D
Quick Check:
Largest breakpoint prefix applies at wide screens [OK]
Hint: Pick the largest breakpoint prefix less than screen width [OK]
Common Mistakes:
Choosing smaller breakpoint sizes
Ignoring lg: prefix effect
Confusing breakpoint order
4. You wrote text-base md:text-lg sm:text-xl but the font size is not increasing on medium screens. What is the problem?
medium
A. Tailwind does not support multiple responsive prefixes on one element
B. The order of responsive prefixes is incorrect; sm: should come before md:
C. You must use lg: instead of md: for medium screens
D. The base font size must be larger than responsive sizes
Solution
Step 1: Understand responsive prefix order
Tailwind applies styles in order of screen size: base, sm, md, lg, xl.
Step 2: Check class order impact
Classes are applied left to right, so md:text-lg is overridden by sm:text-xl because sm: is smaller breakpoint but comes later.
Final Answer:
The order of responsive prefixes is incorrect; sm: should come before md: -> Option B
Quick Check:
Order responsive classes from smallest to largest breakpoint [OK]
Hint: Write responsive classes from smallest to largest breakpoint [OK]
Common Mistakes:
Placing larger breakpoint classes before smaller ones
Assuming Tailwind ignores class order
Confusing breakpoint sizes
5. You want text to be text-sm on mobile, text-base on tablets (640px+), and text-lg on desktops (1024px+). Which Tailwind class combination achieves this?
hard
A. text-sm md:text-base lg:text-lg
B. text-sm sm:text-lg md:text-base
C. text-sm sm:text-base md:text-lg
D. text-base sm:text-sm lg:text-lg
Solution
Step 1: Match breakpoints to screen sizes
Mobile is default (no prefix), tablets start at sm (640px), desktops at lg (1024px). For 1024px+, lg: is correct for desktops.
Step 2: Check class correctness
text-sm default for mobile, md:text-base applies at 768px+, and lg:text-lg applies at 1024px+. This combination ensures text-base on tablets (md breakpoint) and text-lg on desktops (lg breakpoint).
Final Answer:
text-sm md:text-base lg:text-lg -> Option A
Quick Check:
Use default, then md:, then lg: for ascending screen sizes [OK]
Hint: Use default, then md:, then lg: for ascending screen sizes [OK]
Common Mistakes:
Mixing breakpoint order
Using lg: instead of md: for tablets
Setting smaller sizes on larger screens
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.