Skip to content

Tailwind Responsive Design

Tailwind makes responsive design part of every utility class through breakpoint prefixes. This lesson explains Tailwind's mobile-first breakpoint system and shows how to build layouts that adapt cleanly across screen sizes.

What Is Responsive Design in Tailwind?

Tailwind is mobile-first: unprefixed utilities apply at all screen sizes, and prefixed utilities like md:flex only apply at that breakpoint and above. There is no separate "mobile" utility; mobile is simply the default.

This means you write your base styles for small screens first, then layer on breakpoint-prefixed utilities to change the layout as the viewport grows.

<div class="flex flex-col md:flex-row gap-4">
  <div class="w-full md:w-1/2">Column A</div>
  <div class="w-full md:w-1/2">Column B</div>
</div>

On small screens the columns stack vertically at full width; at the md breakpoint (768px) and up, they sit side by side at 50% width each.

Breakpoint Prefix Syntax

class="utility md:utility lg:utility"
  • Unprefixed utilities apply at every screen size (mobile-first default).
  • sm:, md:, lg:, xl:, and 2xl: apply at that breakpoint's minimum width and above.
  • Breakpoints use min-width media queries, so md:flex also applies at lg and xl unless overridden.
  • You can override a breakpoint's utility at a larger breakpoint, like md:flex-row lg:flex-col.

Tailwind Breakpoints Cheatsheet

The default breakpoint scale and how each prefix behaves.

Prefix Min Width Typical Device
(none) 0px All screens, mobile-first default
sm: 640px Large phones, small tablets
md: 768px Tablets
lg: 1024px Small laptops
xl: 1280px Desktops
2xl: 1536px Large desktops
max-md: below 768px Applies only below the md breakpoint
Container queries @container Responsive based on a parent container, not the viewport
Arbitrary breakpoint min-[900px]:flex One-off custom breakpoint value

Mobile-First Thinking

Design for the smallest screen first, then progressively add breakpoint-prefixed utilities as the design needs to change for larger screens. This usually means fewer overrides overall, since most elements look fine simply stacking and expanding.

<h1 class="text-2xl md:text-4xl lg:text-5xl font-bold">
  Responsive Heading
</h1>

The heading starts small on mobile and grows at each larger breakpoint.

Building a Responsive Grid

Combine grid-cols-* with breakpoint prefixes to change how many columns display at each screen size, a very common real-world responsive pattern for card grids and galleries.

<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
  <div class="rounded-lg bg-white p-4 shadow">Card 1</div>
  <div class="rounded-lg bg-white p-4 shadow">Card 2</div>
  <div class="rounded-lg bg-white p-4 shadow">Card 3</div>
</div>

One column on mobile, two on small tablets, three on large screens and above.

Hiding and Showing Content Responsively

Combine hidden with a breakpoint's display utility to show different content, like a mobile menu icon versus a full desktop navigation bar.

<button class="md:hidden">Open Menu</button>
<nav class="hidden md:flex gap-6">
  <a href="/">Home</a>
  <a href="/about">About</a>
</nav>

The button shows only below the md breakpoint; the nav shows only at md and above.

Responsive Design and Core Web Vitals

Search engines use mobile-friendliness and layout stability as ranking signals. Well-structured responsive utilities help avoid layout shift and unreadable text on small screens, both of which hurt Core Web Vitals scores.

  • Always test the smallest breakpoint first; it's what search engine mobile crawlers see.
  • Avoid fixed pixel widths that force horizontal scrolling on small screens.
  • Use responsive text sizing (text-2xl md:text-4xl) instead of one large fixed size everywhere.

Common Mistakes

  • Designing desktop-first and only adding mobile overrides afterward, which usually creates more overrides overall.
  • Forgetting that Tailwind breakpoints are min-width based, so md:flex also affects lg and xl screens.
  • Using sm:hidden alone expecting it to hide only on small screens; you likely want max-sm:hidden or a between-breakpoints pattern instead.
  • Hardcoding pixel-based widths instead of using responsive width and grid utilities.
  • Not testing intermediate breakpoints like md and lg, only checking mobile and the widest desktop size.

Key Takeaways

  • Tailwind's responsive system is mobile-first: unprefixed classes apply everywhere, prefixed classes apply at that breakpoint and up.
  • The default breakpoints are sm (640px), md (768px), lg (1024px), xl (1280px), and 2xl (1536px).
  • Responsive utilities can be combined with any other utility, including grid columns, typography, and display.
  • Use hidden plus a display utility to swap content between mobile and desktop layouts.
  • Arbitrary breakpoints like min-[900px]:flex cover one-off cases the default scale doesn't fit.

Pro Tip

Resize your browser slowly from narrow to wide while developing. Tailwind's mobile-first breakpoints make it easy to spot exactly where a layout should change.