Responsive Design With Breakpoints

Use sm, md, lg and xl prefixes to change styles by screen width.

Syntaxclass="text-base md:text-2xl"

Tailwind is mobile-first. An unprefixed utility applies to every size. A prefixed utility applies from that breakpoint up.

Responsive breakpoints scale upbasesm 640md 768lg 1024xl 1280
Prefixes like md: apply from that width and up (mobile-first).
PrefixMin width
sm:640px
md:768px
lg:1024px
xl:1280px

Resize the preview: the box below is stacked on small screens and turns cyan and wider from md up.

Example

Try it yourself
Loading editor…
Press Run to see the result.

When to use it

  • A developer stacks a two-column layout vertically on mobile by defaulting to flex-col and switching to flex-row at the md breakpoint.
  • A hero section enlarges its heading from text-2xl on phones to text-5xl on desktop using responsive text size prefixes.
  • A sidebar is hidden on small screens with hidden and revealed on large screens with lg:block without writing any media queries.

More examples

Mobile-first column layout

flex-col stacks elements vertically on mobile; md:flex-row switches to a side-by-side layout at the medium (768 px) breakpoint.

Example Β· html
<div class="flex flex-col md:flex-row gap-6">
  <aside class="w-full md:w-64">Sidebar</aside>
  <main class="flex-1">Main content</main>
</div>

Responsive typography

The heading grows through four sizes as the viewport widens, with each breakpoint prefix adding styles on top of the previous.

Example Β· html
<h1 class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl font-bold">
  Responsive Heading
</h1>

Show/hide by breakpoint

hidden hides the desktop nav on small screens; lg:flex reveals it on large screens, while the menu button disappears at the same breakpoint.

Example Β· html
<nav class="hidden lg:flex items-center gap-6">
  <a href="/about">About</a>
  <a href="/pricing">Pricing</a>
</nav>
<button class="lg:hidden">Menu</button>

Discussion

  • Be the first to comment on this lesson.
Responsive Design With Breakpoints β€” Tailwind CSS | SoundsCode