Bird
Raised Fist0
Tailwindmarkup~20 mins

Tailwind with Next.js - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tailwind with Next.js Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ layout
intermediate
2:00remaining
Understanding Tailwind Flexbox in Next.js
You have a Next.js component using Tailwind CSS. What will be the visual layout of the boxes inside the container?

Code:
export default function FlexExample() {
  return (
    <div className="flex flex-col md:flex-row gap-4 p-4">
      <div className="bg-blue-500 text-white p-4">Box 1</div>
      <div className="bg-green-500 text-white p-4">Box 2</div>
      <div className="bg-red-500 text-white p-4">Box 3</div>
    </div>
  )
}
Tailwind
export default function FlexExample() {
  return (
    <div className="flex flex-col md:flex-row gap-4 p-4">
      <div className="bg-blue-500 text-white p-4">Box 1</div>
      <div className="bg-green-500 text-white p-4">Box 2</div>
      <div className="bg-red-500 text-white p-4">Box 3</div>
    </div>
  )
}
ABoxes are arranged horizontally side-by-side on all screen sizes.
BBoxes overlap each other because of conflicting flex classes.
CBoxes are stacked vertically on all screen sizes with no horizontal arrangement.
DBoxes are stacked vertically on small screens and arranged horizontally side-by-side on medium and larger screens.
Attempts:
2 left
💡 Hint
Look at the responsive prefix 'md:' in the class names and what flex-col and flex-row do.
❓ accessibility
intermediate
2:00remaining
Improving Accessibility with Tailwind and Next.js
You want to make a button in a Next.js app styled with Tailwind accessible for screen readers. Which option correctly adds an accessible label to a button that only shows an icon visually?

Code snippet:
<button className="p-2 bg-gray-800 text-white rounded">
  <svg aria-hidden="true" className="w-6 h-6">...</svg>
</button>
Tailwind
<button className="p-2 bg-gray-800 text-white rounded">
  <svg aria-hidden="true" className="w-6 h-6">...</svg>
</button>
AAdd aria-label="Close menu" attribute to the button element.
BAdd <span className="sr-only">Close menu</span> inside the button after the SVG.
CAdd title="Close menu" attribute to the SVG element.
DAdd role="img" to the button element.
Attempts:
2 left
💡 Hint
Screen readers read aria-label on interactive elements like buttons.
📝 Syntax
advanced
2:00remaining
Tailwind Class Conditional Rendering in Next.js
You want to conditionally apply Tailwind classes in a Next.js component based on a boolean state. Which code snippet correctly applies 'bg-green-500' when isActive is true, and 'bg-red-500' when false?

Assume isActive is a boolean state variable.
Tailwind
export default function StatusButton({ isActive }) {
  return (
    <button className={/* fill here */ + " text-white p-2 rounded"}>
      Status
    </button>
  )
}
AclassName={`${isActive ? 'bg-green-500' : 'bg-red-500'} text-white p-2 rounded`}
BclassName={isActive && 'bg-green-500' || 'bg-red-500' + ' text-white p-2 rounded'}
CclassName={isActive ? 'bg-green-500 text-white p-2 rounded' : 'bg-red-500 text-white p-2 rounded'}
DclassName={['bg-green-500', 'bg-red-500'][isActive] + ' text-white p-2 rounded'}
Attempts:
2 left
💡 Hint
Use template literals and the ternary operator inside className.
❓ selector
advanced
2:00remaining
Tailwind Customizing Focus Styles in Next.js
You want to customize the focus ring color on a button using Tailwind in Next.js. Which class combination correctly changes the focus ring to yellow with a 4px width?

Button base classes: p-3 rounded bg-blue-600 text-white
Tailwind
<button className="p-3 rounded bg-blue-600 text-white /* add focus classes here */">
  Click me
</button>
Afocus:outline-none focus:ring-4 focus:ring-yellow-400
Bfocus:outline focus:ring-yellow-400 focus:ring-4
Cfocus:ring focus:ring-yellow-400 focus:ring-4
Dfocus:ring-4 focus:ring-yellow-400 focus:outline-none
Attempts:
2 left
💡 Hint
Tailwind requires 'focus:ring' to enable the ring, then you can set size and color.
🧠 Conceptual
expert
3:00remaining
Next.js and Tailwind CSS: Optimizing for Production
In a Next.js project using Tailwind CSS, which configuration ensures the smallest CSS bundle size in production by removing unused styles?

Choose the correct Tailwind config snippet.
Tailwind
module.exports = {
  content: [/* fill here */],
  theme: {
    extend: {},
  },
  plugins: [],
}
Acontent: ['./src/**/*.{html,js}']
Bcontent: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}']
Ccontent: ['./public/**/*.{js,ts,jsx,tsx}']
Dcontent: ['./styles/**/*.{css,scss}']
Attempts:
2 left
💡 Hint
Tailwind scans files where you write JSX or HTML to find used classes.

Practice

(1/5)
1. What is the main purpose of using Tailwind CSS in a Next.js project?
easy
A. To write custom JavaScript functions
B. To manage server-side routing
C. To quickly style components using utility classes
D. To handle database connections

Solution

  1. Step 1: Understand Tailwind CSS role

    Tailwind CSS provides utility classes for styling HTML elements quickly without writing custom CSS.
  2. Step 2: Identify Next.js features

    Next.js handles routing and server-side rendering, not styling or database management.
  3. Final Answer:

    To quickly style components using utility classes -> Option C
  4. Quick Check:

    Tailwind CSS = Utility-first styling [OK]
Hint: Tailwind is for styling, not logic or routing [OK]
Common Mistakes:
  • Confusing Tailwind with JavaScript logic
  • Thinking Tailwind manages routing or backend
  • Assuming Tailwind replaces Next.js features
2. Which of the following is the correct way to add Tailwind CSS classes to a Next.js component's div element?
easy
A.
Content
B.
Content
C.
Content
D.
Content

Solution

  1. Step 1: Recall JSX syntax for class names

    In React and Next.js, use className with double quotes for CSS classes.
  2. Step 2: Check each option

    <div className="bg-blue-500 text-white p-4">Content</div> uses correct JSX syntax with double quotes. <div class="bg-blue-500 text-white p-4">Content</div> uses plain HTML class, which is invalid in JSX. <div className={bg-blue-500 text-white p-4}>Content</div> treats the classes as a JavaScript expression without proper quotes. <div className=bg-blue-500 text-white p-4>Content</div> lacks quotes around the class names.
  3. Final Answer:

    <div className="bg-blue-500 text-white p-4">Content</div> -> Option A
  4. Quick Check:

    JSX uses className="..." [OK]
Hint: Use className with double quotes in JSX [OK]
Common Mistakes:
  • Using plain class instead of className in JSX
  • Missing quotes around class names
  • Using invalid JSX syntax for className
3. Given this Next.js component using Tailwind CSS, what will be the background color of the button on a small screen?
export default function Button() {
  return (
    <button className="bg-green-500 sm:bg-red-500 text-white p-3">Click Me</button>
  )
}
medium
A. Green background
B. Red background
C. No background color
D. Blue background

Solution

  1. Step 1: Understand Tailwind responsive prefixes

    The class bg-green-500 applies by default. The sm:bg-red-500 applies only on small screens and above (min-width 640px).
  2. Step 2: Identify screen size effect

    On screens smaller than 640px, only bg-green-500 applies. On small screens and larger, bg-red-500 overrides the background.
  3. Final Answer:

    Green background -> Option A
  4. Quick Check:

    Default class applies below sm breakpoint [OK]
Hint: Responsive classes apply only at or above their breakpoint [OK]
Common Mistakes:
  • Assuming sm: classes apply on all screen sizes
  • Ignoring default class without prefix
  • Confusing breakpoint directions
4. You have this Next.js component code:
export default function Header() {
  return (
    <header className="flex justify-center items-center p-4">
      <h1 className="text-2xl font-bold">Welcome</h1>
    </header>
  )
}

But the header content is not centered vertically. What is the likely cause?
medium
A. Using p-4 breaks flexbox layout
B. Missing min-h-screen or height on header to enable vertical centering
C. Tailwind CSS is not installed
D. Incorrect use of justify-center instead of items-center

Solution

  1. Step 1: Understand flexbox vertical centering

    Flexbox vertical centering with items-center works if the container has height. Without height, vertical centering has no effect.
  2. Step 2: Check header height

    The header has padding but no height or min-height. Adding min-h-screen or a fixed height allows vertical centering.
  3. Final Answer:

    Missing min-h-screen or height on header to enable vertical centering -> Option B
  4. Quick Check:

    Flex vertical center needs container height [OK]
Hint: Flex vertical center needs container height [OK]
Common Mistakes:
  • Thinking justify-center controls vertical alignment
  • Assuming padding sets height
  • Ignoring need for Tailwind installation
5. You want to create a responsive navigation bar in Next.js using Tailwind CSS that stacks vertically on mobile and horizontally on desktop. Which combination of Tailwind classes achieves this?
hard
A.
B.
C.
D.

Solution

  1. Step 1: Understand layout direction classes

    flex-col stacks items vertically; flex-row arranges items horizontally.
  2. Step 2: Apply responsive prefixes

    Using flex flex-col md:flex-row means vertical stacking by default (mobile) and horizontal layout on medium screens and above (desktop).
  3. Step 3: Check other options

    <nav className="grid grid-cols-4 md:grid-cols-1 gap-4 p-4">...</nav> uses grid-cols-4 by default, spreading items horizontally on mobile instead of stacking vertically. <nav className="block md:flex-row gap-4 p-4">...</nav> misses flex class, so md:flex-row won't apply properly. <nav className="flex-row flex md:flex-col gap-4 p-4">...</nav> reverses directions incorrectly.
  4. Final Answer:

    <nav className="flex flex-col md:flex-row gap-4 p-4">...</nav> -> Option D
  5. Quick Check:

    flex-col mobile + md:flex-row desktop = responsive nav [OK]
Hint: Use flex-col mobile, md:flex-row desktop for responsive nav [OK]
Common Mistakes:
  • Forgetting to add base flex class
  • Using wrong order of flex-row and flex-col
  • Confusing grid with flex for simple nav layout
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard