Interview Questions
Tailwind CSS Interview Questions Q: What is utility-first CSS and what are its benefits? Utility-first CSS uses small, single-purpose classes (like flex, mt-4, …
Tailwind CSS Interview Questions
Q: What is utility-first CSS and what are its benefits?
Utility-first CSS uses small, single-purpose classes (like flex, mt-4, text-blue-500) directly in HTML instead of writing custom CSS classes. Benefits: no naming bikeshedding, styles colocated with markup, no dead CSS (PurgeCSS removes unused), consistent design tokens, faster iteration. Downsides: verbose markup, need to extract reusable patterns with @apply or components.
Q: How does Tailwind minimize bundle size?
Tailwind scans your content files (configured in content array) and generates only the CSS classes actually used. Unused utilities are purged. The final CSS bundle is typically 5-20KB gzipped — much smaller than full CSS frameworks. In development, Tailwind generates the full stylesheet for fast iteration.
Q: What is @apply and when should you use it?
@apply lets you compose utility classes into a custom CSS class. Use it sparingly for truly reusable UI components (buttons, inputs) where you'd otherwise repeat the same 15 classes everywhere. Avoid over-using it — it defeats the purpose of utility-first and makes it harder to see styles in the markup.
Q: What is the difference between sm:hidden and hidden sm:block?
Tailwind is mobile-first. Breakpoint prefixes apply at that size and up. sm:hidden means "hidden from 640px and up" (visible on mobile). hidden sm:block means "hidden by default (mobile), visible from 640px up". These are opposite patterns for responsive show/hide.
Q: How do you use Tailwind with a component library like React?
Use the cn() or clsx() utility to conditionally combine classes. For component variants, libraries like cva (class-variance-authority) let you define variant-based class maps. Always pass className props to allow customization. Use tailwind-merge (twMerge) to properly merge conflicting Tailwind classes (e.g., merging p-4 with p-8 correctly results in only p-8).