Tailwind CSS interview questions

25 questions from the Tailwind CSS course, each with the correct answer and an explanation. Try to answer before you open the answer.

Utility-First Fundamentals

1. What is a core idea of utility-first CSS?

  1. Avoiding HTML classes entirely
  2. Writing one large class per page
  3. Composing small single-purpose classes directly in markup
  4. Using only inline style attributes
Show answer

Answer: Composing small single-purpose classes directly in markup

Utilities are composed in markup.

Lesson: What Utility-First Means

2. How do you include Tailwind in a v4 stylesheet?

  1. @import "tailwindcss";
  2. @tailwind everything;
  3. <script src="tailwind.css">
  4. require("tailwind")
Show answer

Answer: @import "tailwindcss";

v4 uses a single CSS import.

Lesson: Setting Up Tailwind CSS v4

3. Why does `bg-${color}-500` fail to produce styles?

  1. It needs !important
  2. Template literals are not allowed in HTML
  3. Red is not a Tailwind colour
  4. Tailwind detects complete class names as text, and that string never appears whole
Show answer

Answer: Tailwind detects complete class names as text, and that string never appears whole

Use full class names.

Lesson: How Classes Become CSS

Spacing, Typography and Colour

4. With the default spacing of 0.25rem, how much padding does p-4 give?

  1. 4px
  2. 1rem
  3. 4rem
  4. 0.4rem
Show answer

Answer: 1rem

4 × 0.25rem.

Lesson: Spacing and Sizing

5. Which utility limits text to three lines with an ellipsis?

  1. truncate-3
  2. line-clamp-3
  3. text-3
  4. leading-3
Show answer

Answer: line-clamp-3

truncate is for a single line.

Lesson: Typography

6. What does bg-black/50 produce?

  1. A 50% grey
  2. A black background 50px wide
  3. Black text at 50% size
  4. A black background at 50% opacity
Show answer

Answer: A black background at 50% opacity

Slash adds opacity.

Lesson: Colour and Opacity

Layout With Flexbox and Grid

7. Which utility vertically centres items in a horizontal flex row?

  1. items-center
  2. justify-center
  3. text-center
  4. content-center-x
Show answer

Answer: items-center

Cross-axis alignment.

Lesson: Flexbox

8. How do you make an item span two grid columns?

  1. span-x-2
  2. grid-2
  3. col-span-2
  4. w-2
Show answer

Answer: col-span-2

Column span utilities.

Lesson: CSS Grid

9. What must the parent usually have for an absolute child to position relative to it?

  1. overflow-auto
  2. flex
  3. relative (or another non-static position)
  4. z-0 only
Show answer

Answer: relative (or another non-static position)

Absolute positions against the nearest positioned ancestor.

Lesson: Positioning and Layering

Responsive Design, States and Dark Mode

10. When does md:flex-row apply?

  1. At the md breakpoint and wider
  2. Only on medium screens
  3. Only below md
  4. Only on mobile
Show answer

Answer: At the md breakpoint and wider

Mobile-first: prefixes apply upwards.

Lesson: Mobile-First Breakpoints

11. How do you change a child's colour when its parent card is hovered?

  1. Use dark: on the parent
  2. Add hover: to the child only
  3. Use peer on the child
  4. Add group to the parent and group-hover: to the child
Show answer

Answer: Add group to the parent and group-hover: to the child

group links parent state to children.

Lesson: Hover, Focus, Group and Peer

12. By default, when do dark: utilities apply in Tailwind v4?

  1. Always
  2. When the system prefers a dark colour scheme
  3. Only after 6pm
  4. Only when a .dark class exists
Show answer

Answer: When the system prefers a dark colour scheme

Override with @custom-variant for a toggle.

Lesson: Dark Mode

Customising Tailwind

13. What does declaring --color-brand-500 inside @theme enable?

  1. Nothing until a config file is added
  2. Utilities such as bg-brand-500 and text-brand-500
  3. Only a CSS variable without utilities
  4. A new breakpoint
Show answer

Answer: Utilities such as bg-brand-500 and text-brand-500

Theme variables create utilities.

Lesson: Design Tokens With @theme

14. How do you write a space inside an arbitrary value?

  1. With a comma only
  2. With %20
  3. Spaces are allowed directly
  4. With an underscore, as in grid-cols-[1fr_2fr]
Show answer

Answer: With an underscore, as in grid-cols-[1fr_2fr]

Class names cannot contain spaces.

Lesson: Arbitrary Values and Properties

15. What is a good use of @apply?

  1. Styling third-party or CMS markup you cannot add classes to
  2. Recreating a class for every component
  3. Replacing all utilities in HTML
  4. Defining breakpoints
Show answer

Answer: Styling third-party or CMS markup you cannot add classes to

Use it sparingly.

Lesson: Custom Utilities, Variants and @apply

Building Components

16. Which classes give a disabled button visual feedback?

  1. focus:hidden
  2. hover:opacity-50
  3. disabled:opacity-50 disabled:cursor-not-allowed
  4. opacity-0
Show answer

Answer: disabled:opacity-50 disabled:cursor-not-allowed

The disabled: variant targets :disabled.

Lesson: Buttons and Variants

17. Which variant styles an input whose aria-invalid attribute is true?

  1. dark:
  2. hover:
  3. aria-invalid:
  4. group-invalid-only:
Show answer

Answer: aria-invalid:

ARIA attribute variants.

Lesson: Forms

18. What is the recommended way to reuse a styled button across a React app?

  1. Create a Button component that holds the classes
  2. Copy the class list everywhere
  3. Build class names from string fragments
  4. Use inline style objects only
Show answer

Answer: Create a Button component that holds the classes

Reuse markup through components.

Lesson: Extracting Reusable Components

Modern CSS Features and Accessibility

19. What must you add before @md: variants work?

  1. A JavaScript resize listener
  2. A media query in CSS
  3. The md: variant on the same element
  4. The @container class on an ancestor
Show answer

Answer: The @container class on an ancestor

Mark the container first.

Lesson: Container Queries

20. Which variant disables motion for users who prefer reduced motion?

  1. hover:
  2. motion-reduce:
  3. print:
  4. dark:
Show answer

Answer: motion-reduce:

Respect prefers-reduced-motion.

Lesson: Transitions and Animation

21. What does sr-only do?

  1. Removes content from the DOM
  2. Hides content visually but keeps it readable by screen readers
  3. Shows content only on small screens
  4. Makes text red
Show answer

Answer: Hides content visually but keeps it readable by screen readers

For accessible labels.

Lesson: Accessibility Utilities

Tailwind in Production

22. What does prettier-plugin-tailwindcss do?

  1. Adds dark mode automatically
  2. Compiles Tailwind to JavaScript
  3. Removes unused HTML
  4. Sorts Tailwind classes in a consistent order
Show answer

Answer: Sorts Tailwind classes in a consistent order

Consistent ordering reduces noise.

Lesson: Editor and Formatting Tooling

23. What decides which of two conflicting utilities wins without tooling?

  1. Their order in the generated CSS
  2. Their order in the class attribute
  3. Alphabetical order
  4. The longer class name
Show answer

Answer: Their order in the generated CSS

Use tailwind-merge for predictable overrides.

Lesson: Conditional Classes and Conflicts

24. Where do design tokens usually live in Tailwind v4?

  1. In package.json
  2. Only in tailwind.config.js
  3. In an @theme block in CSS
  4. In HTML meta tags
Show answer

Answer: In an @theme block in CSS

CSS-first configuration.

Lesson: Migrating From v3 to v4

25. Which item belongs on a Tailwind review checklist?

  1. Remove all focus outlines
  2. Use dynamic class name fragments
  3. Every interactive element has a visible focus style
  4. Repeat arbitrary hex colours everywhere
Show answer

Answer: Every interactive element has a visible focus style

Accessibility and maintainability.

Lesson: A Tailwind Project Checklist

← Back to the course