Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 37 ยท Responsive Design and State Variants

Responsive Design with Breakpoints

Learn how Tailwind CSS builds responsive layouts mobile-first with sm, md, lg, xl and 2xl prefixes, max-width variants, ranges and arbitrary breakpoints.

Websites are opened on phones, tablets, laptops and wide monitors, and one layout rarely fits them all. In plain CSS you write media queries in a separate block and repeat selectors. Tailwind turns this around: you add a breakpoint prefix to any utility, right in the HTML, and the utility only applies from that screen width upward.

This lesson explains the default breakpoints, the mobile-first rule that surprises most beginners, and the extra tools for upper limits, ranges and custom widths. Every example below runs in a preview whose width you can change by resizing the editor panel or your browser window.

The default breakpoints

Tailwind v4 ships five breakpoints. Each one is a min-width media query written in rem, so it also respects the learner's font-size settings.

Prefix Minimum width Media query
sm 40rem (640px) @media (width >= 40rem)
md 48rem (768px) @media (width >= 48rem)
lg 64rem (1024px) @media (width >= 64rem)
xl 80rem (1280px) @media (width >= 80rem)
2xl 96rem (1536px) @media (width >= 96rem)

You use a breakpoint by putting its name and a colon in front of a utility: md:flex means "apply display: flex when the viewport is at least 768px wide".

flowchart LR
  A["no prefix<br/>0 and up"] --> B["sm:<br/>640+"] --> C["md:<br/>768+"] --> D["lg:<br/>1024+"] --> E["xl:<br/>1280+"] --> F["2xl:<br/>1536+"]

Each prefix adds rules on top of the ones to its left. Nothing is removed when the screen grows.

Mobile first: unprefixed means "all sizes"

The most common mistake is reading sm: as "on small screens". It is not. A utility with no prefix applies at every width, and a prefixed utility applies from that width upward. So you design the phone layout with plain utilities and then layer changes for bigger screens.

HTML
<div class="text-center sm:text-left">...</div>

Here the text is centered on a phone and left-aligned from 640px up. To target only phones, you change the unprefixed value; you do not look for an xs prefix, because it does not exist (you can add one, as shown later).

Mobile-first columns

The base class grid-cols-1 is the phone layout. sm:grid-cols-2 takes over from 640px, and lg:grid-cols-4 from 1024px. Because lg: comes later in the generated CSS, it wins over sm: when both match.

Changing several things at once

Any utility can be prefixed, not only layout ones. A typical card changes its direction, padding and type size as the screen grows.

A card that rearranges itself

Read the classes aloud as sentences: "a flex column, but from md a flex row with centered items". Keeping the phone styles first and the larger ones after makes this much easier to scan.

Targeting only a range: max-* and stacking

Sometimes you want a style that applies below a width, or between two widths. Tailwind gives you max-* variants, which use max-width queries.

Variant Applies when
max-sm: width is below 640px
max-md: width is below 768px
max-lg: width is below 1024px

Stack a min and a max variant to get a window. md:max-xl:flex applies only from 768px up to (but not including) 1280px.

Show or hide by range

Prefer the mobile-first style (hidden md:block) when you can. max-* variants are for the cases where a rule truly belongs only to small screens, such as a bottom navigation bar that disappears on desktop.

Changing or adding breakpoints

Breakpoints are theme variables in the --breakpoint-* namespace. You can change one or add your own in CSS, using the @theme directive you will meet in detail in The @theme Directive.

CSS
@import "tailwindcss";

@theme {
  --breakpoint-xs: 30rem;
  --breakpoint-3xl: 120rem;
}

This creates xs: and 3xl: variants, and also max-xs: and max-3xl:. To replace the whole set, reset the namespace first with --breakpoint-*: initial; and define only the ones you want. In the browser build you can do the same inside <style type="text/tailwindcss">.

Adding an xs breakpoint

One-off values

When you need a breakpoint only once, use an arbitrary value instead of changing the theme: min-[900px]:grid-cols-3 or max-[600px]:hidden. Use this sparingly. If the same number appears twice, promote it to a theme variable so it has a name.

Responsive design is more than breakpoints

  • Always include <meta name="viewport" content="width=device-width, initial-scale=1"> in the page head, or phones will pretend to be 980px wide and your breakpoints will never fire as expected.
  • Fluid utilities such as w-full, max-w-prose and grid-cols-[repeat(auto-fit,minmax(14rem,1fr))] adapt without any breakpoint. Use them first and add breakpoints for real structural changes.
  • Breakpoints look at the viewport. If a component needs to react to the size of its container instead, use the container queries from Container Queries and More Variants.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does md:flex mean?

    Breakpoint variants are min-width queries, so the utility applies from the breakpoint upward until something overrides it.
  2. 2. Which classes center text on phones but left-align it from 640px?

    The unprefixed utility is the base layout for every width; the sm: utility overrides it from 640px upward.
  3. 3. How do you apply a style only from 768px up to just below 1280px?

    Stacking a min variant (md:) with a max variant (max-xl:) creates a range.
  4. 4. Where do you define a new xs breakpoint in Tailwind v4?

    Breakpoints are theme variables in the --breakpoint-* namespace, so defining one creates the matching variants.

Summary

  • Breakpoint prefixes (sm, md, lg, xl, 2xl) are min-width media queries written in rem.
  • Design the smallest screen with unprefixed utilities, then add prefixed ones for larger screens.
  • max-* variants and stacking such as md:max-xl: target ranges.
  • Add or rename breakpoints with --breakpoint-* theme variables, or use min-[900px]: for a single use.
  • Include the viewport meta tag, or breakpoints will not behave on phones.

Next: State Variants: Hover, Focus and More