Frontend Patterns

Pattern

Responsive Design

Create layouts that adapt gracefully to different screen sizes and devices.

Styling Beginner

Responsive Design

Problem

Interfaces look broken on mobile devices with text cut off, buttons unreachable, and horizontal scrolling required. Desktop-optimized layouts force mobile users to pinch and zoom constantly, while fixed-width designs overflow on tablets. Each device size creates a different broken experience, frustrating users and hurting engagement.

Solution

Adapt layouts to different screen sizes using flexible grids and media queries. This ensures interfaces work across devices without separate mobile and desktop sites.

Example

This example demonstrates responsive design with a container that adapts its width and padding based on screen size using media queries.

.container {
  /* Fluid width that adapts to viewport */
  width: 100%;
  /* But never exceeds 1200px on large screens */
  max-width: 1200px;
  /* Center the container */
  margin: 0 auto;
}

/* On mobile/tablet, add padding */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }
}

Benefits

  • Ensures interfaces work across all device sizes without separate codebases.
  • Improves user experience by adapting layouts to device capabilities.
  • Reduces development and maintenance costs with a single codebase.
  • Supports both current and future device sizes with flexible layouts.

Tradeoffs

  • Requires testing across many device sizes and orientations.
  • Can be complex to design layouts that work well at all breakpoints.
  • May compromise optimal experiences on specific devices for universal compatibility.
  • Adds CSS complexity with media queries and responsive units.
Stay Updated

Get New Patterns
in Your Inbox

Join thousands of developers receiving weekly insights on frontend architecture patterns

No spam. Unsubscribe anytime.