FrontendDeveloper.in

Tailwind CSS Interview Questions

  • Question 1

    What is Tailwind CSS and why do teams use it?

    Tailwind CSS is a utility-first framework where you compose UI with small, single-purpose classes directly in markup.

    Teams use it for speed, consistency, and fewer context switches between HTML and CSS files.

  • Question 2

    What is utility-first CSS?

    Utility-first means styling is built from low-level classes like p-4, text-sm, flex, and bg-slate-900.

    Instead of writing many custom selectors, you compose styles declaratively per component.

  • Question 3

    How does Tailwind remove unused CSS?

    Tailwind scans your source files and generates only classes that appear in your content paths.

    This keeps production CSS small and avoids shipping a huge unused stylesheet.

  • Question 4

    What is the Tailwind config used for?

    tailwind.config (or v4 equivalent config patterns) is used to define theme tokens, spacing scales, custom colors, plugins, and content scanning.

    It centralizes design system decisions.

  • Question 5

    How do you create reusable styles in Tailwind?

    You can extract repeated class sets into component abstractions (React components) or use utilities like @apply where appropriate.

    Prefer component extraction for maintainability and explicit API boundaries.

  • Question 7

    What are state variants in Tailwind?

    Variants apply styles for interaction/state contexts, such as hover:, focus:, disabled:, and group-hover:.

    They reduce custom CSS for common UI interactions.

  • Question 8

    What is `dark:` in Tailwind?

    dark: applies classes when dark mode is active based on the configured strategy (class or media).

    Example: bg-white dark:bg-slate-900.

  • Question 9

    What is arbitrary value syntax?

    Arbitrary values let you use custom values directly in class names when needed.

    Example: w-[42rem] or shadow-[0_8px_24px_rgba(0,0,0,0.12)].

  • Question 10

    How do you avoid class name bloat in JSX?

    Use helper utilities (clsx, cva) and split UI into smaller components.

    Keep classes grouped by layout, spacing, typography, colors, and states for readability.

  • Question 11

    What is `@layer` in Tailwind-based styles?

    @layer allows organizing custom CSS into base, components, and utilities so Tailwind can merge and order styles correctly.

    It helps when you need project-specific additions.

  • Question 14

    How do peer variants work?

    peer lets one element react to a sibling's state.

    Common for forms: input has peer, error/help text uses peer-invalid:block.

Get LinkedIn Premium at Rs 399