Skip to content
tezvyn:

Tailwind CSS: Styling Directly in Your HTML

Source: tailwindcss.comMediumHow cards are made

Tailwind CSS: Styling Directly in Your HTML

Tailwind CSS lets you build designs by composing utility classes like flex and pt-4 directly in your HTML. This avoids context-switching for rapid UI development. The main footgun is creating verbose, unreadable markup if not managed well.

Why it exists

Tailwind was created to accelerate UI development by eliminating the constant context switch between HTML and CSS files. Instead of inventing semantic class names and then defining their styles elsewhere, developers can apply styles directly from a pre-existing, comprehensive toolkit within their markup.

The mental model

Think of Tailwind not as a UI kit with pre-built components (like Bootstrap's cards), but as a low-level styling toolkit. It provides thousands of tiny, single-purpose utility classes that act like Lego bricks. Each class, like text-lg or bg-blue-500, maps almost directly to a single CSS property, giving you full creative control from within your HTML.

How it works

You build designs by adding utility classes to an element's class attribute. For example, pt-4 sets padding-top, flex sets display: flex, and rotate-90 applies a transform. For dynamic styling, you use prefixes. Responsive design is handled with screen-size prefixes (sm:, md:, lg:), so md:text-left applies text-align: left only on medium screens and up. Similarly, the dark: prefix applies styles only in dark mode.

When to use it

Use Tailwind for projects that require rapid prototyping or the creation of a bespoke, consistent design system. It excels when you want granular control over styling without the constraints of pre-designed components. Its built-in support for modern features like container queries, CSS variables, and cascade layers makes it ideal for complex applications.

When not to use it

Avoid Tailwind if you strictly prefer the classic separation of concerns, where HTML is for structure and CSS is purely for styling. For very small projects with minimal styling, the setup can be overkill. The biggest risk is creating unmaintainable "class soup"—long, unreadable class lists—if your team doesn't abstract repetitive patterns into components.

One canonical example

To build a simple responsive card, you might write: . This single line creates a padded, white, shadowed card. On small screens (flex-col), its items are in a column, but on small screens and up (sm:flex-row), they switch to a row, demonstrating responsive design directly in the markup.

Interview question

What is the fundamental approach Tailwind CSS takes to styling web interfaces?

  • a.It automatically analyzes HTML structure to generate optimized, minimal CSS files.
  • b.It offers a library of pre-built, semantic components for common UI patterns.
  • c.It provides low-level utility classes that directly apply individual CSS properties.Correct
  • d.It encourages writing custom CSS rules within <style> tags for each component.
Why?

Option C correctly describes Tailwind's core philosophy of providing granular, single-purpose utility classes that directly translate to CSS properties. Option B describes a component-based framework like Bootstrap, which the card explicitly contrasts with Tailwind's utility-first approach.

Just read this? Test yourself on what you have been reading.

Read the original → tailwindcss.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.

See open roles