Skip to main content

HTML Responsive Web Design

Responsive web design is about making pages that look good on all devices. A responsive page automatically adjusts for different screen sizes and viewports.


What is Responsive Web Design?

Responsive web design uses HTML and CSS to automatically resize, hide, shrink, or enlarge a website so it looks good on all devices, from desktops to tablets to phones.


Setting The Viewport

To make a site responsive, add the viewport <meta> tag to every page. It tells the browser how to control the page's size and scaling.

Example

A page that includes the viewport meta tag.

Prompt
A responsive page that includes the viewport meta tag (width=device-width, initial-scale=1.0) in the head, with a heading and paragraph in the body.
Output: complete HTML page

Responsive Images

Responsive images scale nicely to fit any browser size. If the CSS width property is set to 100%, the image scales up and down, but it can grow larger than its original size. Using max-width at 100% instead lets the image scale down but never grow beyond its original size.

Using width

An image with width set to 100%.

Prompt
A page with an image set to width:100% via the style attribute, so it scales up and down with the browser (and can grow larger than its original size).
Output: complete HTML page

Using max-width

An image with max-width set to 100%.

Prompt
A page with an image set to max-width:100% and height:auto, so it scales down if needed but never grows larger than its original size.
Output: complete HTML page

Show Different Images Depending on Browser Width

The <picture> element lets you show different images for different browser window sizes.

Example

Different flower images at different widths.

Prompt
A page using the picture element to show different flower images at different browser widths: a small flower up to 600px, a larger one up to 1500px, and a default, with a fallback img.
Output: complete HTML page

Responsive Text Size

Text size can be set in vw units, which means viewport width, so the text follows the size of the browser window. 1vw is 1% of the viewport width, so if the viewport is 50cm wide, 1vw is 0.5cm.

Example

A heading sized in viewport-width units.

Prompt
A page with an h1 whose font size is set in viewport-width units (10vw), so the text scales with the browser window. Text reads "Hello World".
Output: complete HTML page

Media Queries

Besides resizing text and images, responsive pages often use media queries. With a media query you can define completely different styles for different browser sizes, such as showing columns side by side on large screens and stacking them on small screens.

Example

Columns that stack on screens 800px or smaller.

Prompt
A page with three columns (left, main, right) that sit side by side on large screens using float, and stack vertically on screens 800px or smaller using a media query.
Output: complete HTML page

Responsive Web Page - Full Example

A responsive web page should look good on large desktop screens and on small mobile phones.


Responsive Web Design - Frameworks

All popular CSS frameworks offer responsive design. They are free and easy to use.


Bootstrap

Bootstrap is another popular CSS framework for responsive design.

Example

A responsive page built with Bootstrap 5.

Prompt
A responsive page built with Bootstrap 5 (linked from its CDN): a full-width primary-colored header and a three-column row of placeholder content.
Output: complete HTML page