Sub topic 3
The default breakpoints
This chapter assumes you know basic HTML and CSS, including flexbox and grid. It also assumes you have used Tailwind utilities such as flex, p-4 and text-lg, and that you know what a CSS media query is. Here you will learn the five default breakpoints, what each one compiles to, and how to read them correctly.
What a breakpoint is in Tailwind
A breakpoint is a viewport width at which a style rule starts to apply. Tailwind gives each breakpoint a prefix. When you write md:flex, Tailwind generates a rule that wraps display: flex in a media query. The query checks that the viewport is at least a certain width.
Tailwind ships with five breakpoints. They are the same in v3 and v4, apart from how they are written in the generated CSS.
| Prefix | Minimum width | Media query |
|---|---|---|
| `sm` | 640px (40rem) | `@media (min-width: 640px)` |
| `md` | 768px (48rem) | `@media (min-width: 768px)` |
| `lg` | 1024px (64rem) | `@media (min-width: 1024px)` |
| `xl` | 1280px (80rem) | `@media (min-width: 1280px)` |
| `2xl` | 1536px (96rem) | `@media (min-width: 1536px)` |
Tailwind v4 writes these values in rem, so they scale with the user's font size. Tailwind v3 uses pixels. The widths are equivalent at the default font size.
There is no prefix for widths below 640px. Those widths are covered by the unprefixed utilities, which apply everywhere.
Every prefix means "this width and wider"
Each prefix uses min-width. A prefixed utility applies at its breakpoint and stays applied at every larger width, unless a larger prefix overrides it.
<p class="text-sm md:text-base xl:text-lg">
Text size changes at 768px and again at 1280px.
</p>This paragraph resolves as follows:
- Below 768px,
text-smapplies. - From 768px up to 1279px,
md:text-baseoverrides it. - From 1280px up,
xl:text-lgoverrides both.
The diagram shows the same idea as ranges on a width axis.
Seeing the breakpoints in a layout
The next example uses three of the breakpoints on one grid. The unprefixed class sets the layout for the narrowest screens. Each prefix then changes it at a larger width.
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div class="rounded border p-4">One</div>
<div class="rounded border p-4">Two</div>
<div class="rounded border p-4">Three</div>
</div>| Viewport width | Active column class | Result |
|---|---|---|
| 0 to 639px | `grid-cols-1` | One column |
| 640 to 1023px | `sm:grid-cols-2` | Two columns |
| 1024px and up | `lg:grid-cols-3` | Three columns |
The md prefix is not used here. That is fine. You only add a prefix where the layout needs to change, and a gap in the sequence just means the previous rule carries through.
Breakpoints are not device names
The names are small, medium, large and so on, but the values are widths, not devices. A 768px viewport can be a tablet in portrait, a narrow desktop window, or a phone in landscape with a large display. The breakpoint cannot tell the difference, and you should not try to make it.
Choose breakpoints by looking at where your content breaks. If a three-column grid looks cramped at 900px, move the change to lg. If it looks fine, leave it alone.
Important: sm does not mean "small screens"
The most common mistake is reading sm: as "on small screens only". Because the query is min-width: 640px, sm: applies to small screens and everything larger.
<div class="sm:text-center">
Centered from 640px up, left-aligned below that.
</div>On a 375px phone, this text is not centered. On a 1400px desktop, it is. If you want the centered style on phones, write the unprefixed class, text-center, and use a prefix only to change it at a larger width.
Checking your understanding
Exercise
A card has the classes p-2 md:p-6 xl:p-10. What padding does it have at viewport widths of 500px, 800px and 1300px?
Show answer
At 500px it has p-2, because no prefixed rule applies yet. At 800px it has md:p-6, because the viewport is at least 768px but below 1280px. At 1300px it has xl:p-10, because the viewport is at least 1280px and xl overrides md.
Exercise
A developer writes <div class="sm:hidden"> expecting the div to disappear on phones only. What happens at 400px and at 900px, and how should it be written to hide it on phones only?
Show answer
At 400px the div is visible, because sm: applies only from 640px up. At 900px it is hidden, which is the opposite of the intent. To hide it on phones only, show it from the breakpoint upward: hidden sm:block.