Course contentsShow
← Web Development
Lesson 633 of 2,98211. Utility-First CSS with TailwindFree lesson

Breakpoint Prefix Syntax

Learning the sm:, md:, lg:, xl:, and 2xl: prefixes and how to apply utilities conditionally at each breakpoint.

Breakpoint Prefix Syntax

You'll learn how to apply Tailwind utilities conditionally at different screen sizes using breakpoint prefixes.

The Core Idea

Tailwind's breakpoint prefix syntax lets you apply utilities only when the viewport reaches a certain width. Instead of writing media queries manually, you simply prefix any utility class with sm:, md:, lg:, xl:, or 2xl: followed by a colon.

Think of it like setting rules for different rooms in your house: "In the small room, use this furniture arrangement. In the large room, use that arrangement." Each breakpoint is a different "room size" for your layout.

How It Works

The syntax is straightforward:

<div class="text-sm md:text-lg xl:text-2xl">
  This text grows larger on bigger screens
</div>

Here's what each prefix does:

  • No prefix: Applies at all screen sizes (mobile-first base)
  • sm:: Applies at 640px and above
  • md:: Applies at 768px and above
  • lg:: Applies at 1024px and above
  • xl:: Applies at 1280px and above
  • 2xl:: Applies at 1536px and above

Tailwind is mobile-first, meaning unprefixed utilities apply to small screens, and prefixed utilities override them as the screen grows.

Practical Example

<div class="w-full md:w-1/2 lg:w-1/3">
  Full width on mobile, half on tablets, third on desktops
</div>

You can mix breakpoints on the same element as needed—just add multiple prefixed classes.

Key Takeaway: Breakpoint prefixes (sm:, md:, lg:, xl:, 2xl:) let you apply any utility conditionally at specific viewport widths, enabling responsive design without writing media queries.