🔥 0
0
Lesson 7 of 10 15 min +85 XP

Responsive Design

Tailwind's responsive design is mobile-first and incredibly intuitive.

Breakpoints

Tailwind's default breakpoints:

PrefixMin WidthTypical Device
sm:640pxLarge phones
md:768pxTablets
lg:1024pxLaptops
xl:1280pxDesktops
2xl:1536pxLarge screens

Mobile-First Approach

Start with mobile styles, then add breakpoint prefixes for larger screens:

<!-- Mobile: 1 column, Tablet: 2 columns, Desktop: 4 columns -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
  <div>Card 1</div>
  <div>Card 2</div>
  <div>Card 3</div>
  <div>Card 4</div>
</div>
See it live (resize browser to see changes):
Card 1
Card 2
Card 3
Card 4

This grid changes from 1 to 2 to 4 columns as screen widens

Responsive Text

<!-- Text grows with screen size -->
<h1 class="text-2xl md:text-4xl lg:text-6xl font-bold">
  Responsive Heading
</h1>
See it live:

Responsive Heading

Text size: text-2xl → md:text-3xl → lg:text-4xl

Responsive Spacing

<!-- Padding increases on larger screens -->
<div class="p-4 md:p-8 lg:p-12 bg-blue-100">
  Responsive padding
</div>
See it live:
This padding grows: p-4 → md:p-8 → lg:p-12

Show/Hide Elements

<!-- Hidden on mobile, visible on desktop -->
<div class="hidden md:block">
  Desktop only content
</div>

<!-- Visible on mobile, hidden on desktop -->
<div class="block md:hidden">
  Mobile only content
</div>
See it live:
Mobile only (hidden on desktop)

Resize your browser to see elements appear/disappear

Responsive Flexbox

<!-- Stack on mobile, row on desktop -->
<div class="flex flex-col md:flex-row gap-4">
  <div class="flex-1">Sidebar</div>
  <div class="flex-1">Main content</div>
</div>
See it live:
Sidebar
Main Content

Stacks vertically on mobile, horizontal on tablet+

Practical Examples

Responsive Navigation

<nav class="bg-white shadow">
  <div class="flex items-center justify-between h-16 px-4">
    <div class="text-xl font-bold">Logo</div>

    <!-- Desktop menu -->
    <div class="hidden md:flex items-center gap-6">
      <a href="#">Home</a>
      <a href="#">About</a>
      <button class="bg-blue-600 text-white px-4 py-2 rounded-lg">
        Sign Up
      </button>
    </div>

    <!-- Mobile menu button -->
    <button class="md:hidden p-2">
      <svg class="w-6 h-6">...</svg>
    </button>
  </div>
</nav>
See it live:

Responsive Hero Section

<section class="py-12 md:py-24 px-4">
  <div class="flex flex-col md:flex-row items-center gap-8">
    <div class="flex-1 text-center md:text-left">
      <h1 class="text-3xl md:text-5xl font-bold">
        Build Better Products
      </h1>
      <p class="mt-4 text-lg text-gray-600">
        Create stunning websites with Tailwind CSS.
      </p>
    </div>
    <div class="flex-1">
      <img src="..." class="rounded-xl shadow-lg">
    </div>
  </div>
</section>
See it live:

Build Better Products

Create stunning websites with Tailwind CSS. No design skills required.

Hero Image

Responsive Card Grid

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

Feature One

Description of this feature.

2

Feature Two

Description of this feature.

3

Feature Three

Description of this feature.

1 column → sm:2 columns → lg:3 columns

Key Takeaways

  • Mobile-first: Base styles apply to all, breakpoints add larger screen styles
  • Breakpoints: sm (640), md (768), lg (1024), xl (1280), 2xl (1536)
  • Prefix any utility: md:text-lg, lg:flex-row, xl:grid-cols-4
  • Show/Hide: hidden md:block or md:hidden
  • Stack pattern: flex-col md:flex-row is very common

Next, let's add interactivity with states!

🧠 Quick Quiz

Test your understanding of this lesson.

1

What does 'md:text-lg' mean?

2

Which breakpoint is for tablets (768px)?

3

What's 'mobile-first' design?

Grid Layouts