Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Responsive Design with Tailwind | Section
Styling Svelte Applications with Tailwind CSS

Responsive Design with Tailwind

Stryg for at vise menuen

Modern frontend applications should work across many different screen sizes. A layout that looks good on a desktop may not work well on a mobile device.

Tailwind makes responsive design much easier through responsive utility prefixes.

How Responsive Utilities Work

Tailwind allows developers to apply different styles at different screen sizes using breakpoint prefixes.

For example:

<div class="text-sm md:text-xl">
  Responsive Text
</div>
  • text-sm applies on smaller screens;
  • md:text-xl applies on medium screens and larger.

This allows layouts and styling to adapt automatically.

Common Tailwind Breakpoints

Responsive classes can be combined with almost any Tailwind utility.

Building a Responsive Layout

Open App.svelte and add the following code:

<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
  <div class="bg-purple-200 p-4 rounded-lg">
    Card 1
  </div>

  <div class="bg-purple-200 p-4 rounded-lg">
    Card 2
  </div>

  <div class="bg-purple-200 p-4 rounded-lg">
    Card 3
  </div>
</div>

On small screens, the layout uses one column.

On medium screens and larger, it switches to three columns automatically.

Responsive Spacing and Sizing

Responsive utilities also work with spacing and sizing.

<div class="p-4 md:p-8">
  Responsive Padding
</div>

The padding increases on larger screens.

This helps layouts feel more balanced across devices.

Why Responsive Design Matters

Responsive design is essential in modern frontend development because users access applications from:

  • Phones;
  • Tablets;
  • Laptops;
  • Large desktop screens.

Frontend interfaces should remain usable and visually clean across all devices.

question mark

What will happen in the following layout on smaller screens?

Vælg det korrekte svar

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 5

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Sektion 1. Kapitel 5
some-alt