Tailwind CSS Questions with Answers

14 practice questions on Tailwind CSS (Modern Web (Next.js, PWA, Performance)) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

Why does Tailwind produce small CSS files in production even though it has thousands of utilities?

  1. It removes every class that is used more than once in the code
  2. It loads each utility class lazily from a CDN at runtime
  3. It compresses all utilities into a single CSS custom property
  4. It emits only the classes found in your source files

Answer: D. It emits only the classes found in your source files

Explanation

Tailwind scans your templates for class names and emits CSS only for the ones it finds.

Step-by-step solution

  1. Tailwind scans your source files for class names.
  2. It emits CSS only for the classes it finds there.
  3. So the output contains only the utilities that the project uses (option D).

Why the other options are wrong

  • A. Duplicate classes are not removed by count; unused classes are removed.
  • B. Tailwind does not load classes lazily from a CDN.
  • C. Utilities are not compressed into one custom property.

Tip: Keep full class names in source so the scanner can find them.

Question 2Easy

In a mobile-first framework, the unprefixed class text-sm with md:text-lg means:

  1. Small text by default, larger text from md upwards
  2. The two classes conflict and neither is applied
  3. Large text on small screens, small text from md upwards
  4. Small text only on md screens and nothing elsewhere

Answer: A. Small text by default, larger text from md upwards

Explanation

Unprefixed utilities apply at all sizes; md: overrides from the md breakpoint up.

Step-by-step solution

  1. Unprefixed utilities apply at all screen sizes.
  2. The md prefix overrides them from the md breakpoint upwards.
  3. So text is small by default and larger from md (option A).

Why the other options are wrong

  • B. The classes do not conflict; the prefixed one overrides at its breakpoint.
  • C. The order is reversed: small text is the default in mobile-first.
  • D. The small class applies at all sizes, not only at md.

Tip: Mobile-first: write the base class first, then add larger breakpoint overrides.

Question 3Easy

In Tailwind, what does the class md:flex mean?

  1. Apply display: flex only on screens narrower than md
  2. Apply display: flex at the md width and wider
  3. Apply display: flex only in print stylesheets
  4. Apply display: flex only when the element is focused

Answer: B. Apply display: flex at the md width and wider

Explanation

Tailwind breakpoints are mobile-first min-width media queries: md:flex applies at the md width and larger.

Step-by-step solution

  1. Tailwind breakpoints are mobile-first min-width media queries.
  2. Md:flex is applied from the md width upwards.
  3. So display flex applies at the md width and wider (option B).

Why the other options are wrong

  • A. Prefixed classes apply from the breakpoint up, not below it.
  • C. Print styles use a different variant, not md.
  • D. Focus styles use a focus variant, not md.

Tip: Tailwind responsive prefixes apply at that width and above; start with the mobile class unprefixed.

Question 4Easy

What does "utility-first" CSS, as in Tailwind, mean?

  1. Composing small single-purpose classes like p-4 in markup
  2. Using only CSS-in-JS libraries to generate scoped styles
  3. Writing one large semantic class per component in a separate file
  4. Using inline style attributes for every element on the page

Answer: A. Composing small single-purpose classes like p-4 in markup

Explanation

Utility-first frameworks provide many low-level classes that you compose in markup instead of writing custom CSS for each component.

Step-by-step solution

  1. Utility-first CSS provides many small classes for single properties.
  2. You compose those classes directly in the markup.
  3. So utility-first means composing small single-purpose classes like p-4 (option A).

Why the other options are wrong

  • B. CSS-in-JS is a different approach, not what utility-first means.
  • C. One large semantic class per component is the opposite of utility-first.
  • D. Inline styles on every element is not utility-first CSS.

Tip: Compose small utility classes in markup rather than writing custom CSS for each component.

Question 5Medium

What does the dark:bg-gray-900 class do?

  1. Applies the background when dark mode is active
  2. Darkens the current background by 90 percent
  3. Applies the background only on very small screens
  4. Sets the background when the element is disabled

Answer: A. Applies the background when dark mode is active

Explanation

The dark: variant applies a utility when dark mode is active, by default via prefers-color-scheme or optionally via a class/selector strategy.

Step-by-step solution

  1. The dark variant applies a utility only when dark mode is active.
  2. Dark mode is set by prefers-color-scheme or by a class, depending on the setup.
  3. So dark:bg-gray-900 sets that background when dark mode is on (option A).

Why the other options are wrong

  • B. It sets a fixed background colour; it does not darken by a percentage.
  • C. Screen size uses the breakpoint prefixes, not dark.
  • D. The disabled state uses a different variant.

Tip: Pair each light colour class with a dark: variant when the design needs dark mode.

Question 6Medium

A common criticism of utility-first CSS is long class lists in markup. What is the usual recommended remedy?

  1. Use !important on every repeated utility class
  2. Extract repeated markup into reusable components
  3. Replace all utilities with inline style objects
  4. Move every utility into one global stylesheet

Answer: B. Extract repeated markup into reusable components

Explanation

Reusing a component (or template partial) keeps the utilities in one place, so repetition is handled by the component, not by new CSS classes.

Step-by-step solution

  1. Long class lists become a problem when the same markup is repeated.
  2. The usual fix is to extract the repeated markup into a reusable component.
  3. The component then holds the utilities in one place (option B).

Why the other options are wrong

  • A. !important on every class makes styles harder to override and is not the remedy.
  • C. Inline style objects drop the utility approach and are harder to maintain.
  • D. One global stylesheet defeats the point of utility classes.

Tip: Extract a component when the same class list appears more than once.

Question 7Medium

Why does Tailwind discourage building class names dynamically, such as "text-" + color + "-500"?

  1. The browser cannot apply classes that were built at runtime
  2. Dynamic classes override every other utility on the element
  3. The build scans for full class names, so that CSS is never generated
  4. String concatenation in JSX throws a runtime error in React

Answer: C. The build scans for full class names, so that CSS is never generated

Explanation

Class detection is a plain-text scan, so partial strings are not recognised. Map values to full class names instead.

Step-by-step solution

  1. Tailwind finds classes by scanning the source for complete class names as plain text.
  2. A string built at runtime, like text- plus a colour, has no full class name in the source.
  3. So the CSS for it is never generated (option C).

Why the other options are wrong

  • A. Classes are applied at runtime; the problem is that the CSS was not generated.
  • B. A dynamic class does not override other utilities on its own.
  • D. String concatenation does not throw in React.

Tip: Map values to complete class names, such as a lookup object, so the scanner sees them.

Question 8Medium

What does the group / group-hover: pattern let you do?

  1. Apply one class to all siblings at once
  2. Hover several unrelated elements together at once
  3. Style a child when its marked parent is hovered
  4. Group media queries into one breakpoint

Answer: C. Style a child when its marked parent is hovered

Explanation

Add "group" to a parent and use group-hover:... on descendants to style them based on the parent state.

Step-by-step solution

  1. Add the group class to a parent element.
  2. Use group-hover on a child to style it when the parent is hovered.
  3. So the child is styled based on the state of its marked parent (option C).

Why the other options are wrong

  • A. It styles children of a parent based on its state, not all siblings at once.
  • B. It is tied to one marked parent, not unrelated elements.
  • D. Media queries are handled by breakpoint prefixes, not groups.

Tip: Use the group class on the parent and group-hover on children for hover cards and menus.

Question 9Hard

Two classes on one element, p-2 and p-4, both come from Tailwind. Which padding wins?

  1. Always the class written first in the class attribute string
  2. Neither; the browser averages them to padding: 0.75rem
  3. Always the class written last in the class attribute string
  4. Whichever rule comes later in the generated CSS file

Answer: D. Whichever rule comes later in the generated CSS file

Explanation

Class attribute order has no effect on the cascade; with equal specificity the later rule in the stylesheet wins, which is why conflicting utilities should be avoided.

Step-by-step solution

  1. Both p-2 and p-4 set the same padding property with the same specificity.
  2. Class attribute order has no effect on the cascade.
  3. The later rule in the generated stylesheet wins (option D).

Why the other options are wrong

  • A. The order of words in the class attribute does not decide the winner.
  • B. The browser does not average the values.
  • C. The class attribute order is not what wins; the stylesheet order is.

Tip: Avoid two utilities for the same property on one element; pick one.

Question 10Hard

A design system wants Tailwind utilities like bg-brand to follow a theme colour that can change at runtime. What is a common approach?

  1. Replace bg-brand with inline styles computed by JavaScript on every render
  2. Define the theme colour as a CSS custom property and map the utility to it
  3. Regenerate the Tailwind CSS file in the browser whenever the theme changes
  4. Use arbitrary values with a random colour so each build looks different

Answer: B. Define the theme colour as a CSS custom property and map the utility to it

Explanation

Mapping a theme token to var(--brand) lets you switch the variable at runtime (e.g. per theme) without rebuilding CSS.

Step-by-step solution

  1. A custom property holds the theme colour and can be changed at runtime.
  2. The Tailwind utility is mapped to read that property, such as var(--brand).
  3. Changing the variable switches the colour without rebuilding the CSS (option B).

Why the other options are wrong

  • A. Inline styles on every render are slow and bypass the utility approach.
  • C. Regenerating the CSS in the browser is not needed for a runtime theme.
  • D. Random colours in arbitrary values do not give a theme.

Tip: Map design tokens to CSS custom properties to support runtime themes.

Practise all 14 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Modern Web (Next.js, PWA, Performance) topics · All topics