Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - CSS Responsive Design


CSS Responsive Design

Responsive design ensures that web pages look good on all devices - from large desktop monitors to small smartphones. It automatically adjusts layout, images, and text to fit the screen size.


What is Responsive Design?

A responsive website adapts to the user's device by changing layout, size, and proportions dynamically. It eliminates the need for separate mobile and desktop versions of a site.

  • Uses flexible layouts (percentages or fr units).
  • Uses responsive images that scale with the container.
  • Uses CSS media queries to apply styles at different screen widths.

Setting the Viewport

Add this meta tag inside the <head> of your HTML to ensure proper scaling on all devices:

Example

Responsive viewport tag:

<meta name='viewport' content='width=device-width, initial-scale=1.0'>

Without this tag, mobile browsers will render the page at a fixed width and scale it down, which can make your layout look too small.


Responsive Layouts with Percentages

Instead of fixed pixel widths, use percentage-based widths so that elements scale with the viewport.

Example

Flexible width:

.container {
  width: 80%;
  margin: auto;
  background-color: lightgray;
  padding: 10px;
}
Try it Yourself »

Responsive Images

Images can scale automatically to fit their containers using max-width: 100%; and height: auto;.

Example

Responsive image:

img {
  max-width: 100%;
  height: auto;
}
Try it Yourself »

CSS Media Queries

Media queries let you apply different CSS styles depending on the screen size or device type.

Example

Media query for small screens:

@media (max-width: 600px) {
  body { background-color: lightblue; }
}
Try it Yourself »

This will change the background color to light blue when the screen width is 600px or less.


Common Breakpoints

Typical screen width breakpoints for responsive design:

DeviceBreakpoint
Small phonesmax-width: 480px
Tabletsmax-width: 768px
Laptopsmax-width: 1024px
Desktops1200px and above

Responsive Columns

You can make flexible multi-column layouts that stack on smaller screens.

Example

Responsive columns using media queries:

.container {
  display: flex;
  gap: 10px;
}

.column {
  flex: 1;
  background: lightgray;
  padding: 20px;
}

@media (max-width: 600px) {
  .container { flex-direction: column; }
}
Try it Yourself »

Responsive Text

Use vw (viewport width) units to make text scale with screen size.

Example

Responsive text:

h1 { font-size: 6vw; } /* 6% of the viewport width */
Try it Yourself »

Responsive Frameworks

Frameworks like W3.CSS and Bootstrap include built-in responsive grids and classes. They make it faster to build layouts that look good on any screen.

Tip: W3.CSS is lightweight and mobile-first by default - an excellent way to start building responsive pages quickly.


Summary

  • Responsive design makes websites look good on all devices.
  • Use the viewport meta tag for proper scaling.
  • Use flexible layouts and responsive images.
  • Apply media queries for different screen sizes.
  • Consider using frameworks like W3.CSS or Bootstrap.

Next, you'll learn about CSS Units - including pixels, percentages, ems, rems, and viewport units to size elements consistently across devices.

Next » CSS Units


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.