Apollo Editor
Windows 10 & 11 Buy now · $69.95
HTML & CSS basics

How to Make a Website Responsive So It Works on Phones and Tablets

Make any website responsive: the viewport tag, flexible layouts, responsive images, media queries and how to test pages at phone and tablet sizes.

Updated 5 minute read The Apollo Editor team

To make a website responsive, add the viewport meta tag to every page, build layouts with flexible widths (percentages, Flexbox or Grid) instead of fixed pixel widths, make images scale with max-width: 100%, and use CSS media queries to adjust the design at smaller screen sizes. Then test each page at phone, tablet and desktop widths.

This guide goes through each of those steps in order, with short code examples, and ends with a checklist for testing your pages before you publish.

Step 1: Add the viewport meta tag

Without this tag, phones pretend to be a wide desktop screen and shrink the whole page down, so text becomes tiny. Add this line inside the <head> of every page:

<meta name="viewport" content="width=device-width, initial-scale=1">

It tells the browser to use the real width of the device and start at normal zoom. Nothing else in this guide works properly until it is in place. Avoid adding maximum-scale=1 or user-scalable=no, because they stop people from zooming in, which hurts accessibility.

Step 2: Replace fixed widths with flexible ones

Older sites often set a wrapper to something like width: 960px;. On a phone around 400 pixels wide, that forces sideways scrolling. Instead, let the layout shrink while capping how wide it gets on big screens:

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

Some general rules:

  • Use max-width rather than width for containers.
  • Use percentages, fr units or Flexbox for columns, not fixed pixel widths.
  • Use relative units such as rem for font sizes and spacing, so text respects the visitor's settings.
  • Avoid fixed heights on boxes that contain text. Text wraps onto more lines on small screens and will overflow a fixed height.
  • Add box-sizing: border-box; to all elements so padding does not push boxes wider than you planned.

Step 3: Use Flexbox and Grid for layout

Modern layout tools adapt to the screen with very little code. A grid of cards that fits as many columns as there is room for, then drops to one column on a phone, needs just one rule:

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }

A row of items that wraps onto new lines when space runs out works the same way with Flexbox:

.features { display: flex; flex-wrap: wrap; gap: 20px; }

If your site still uses HTML tables for layout, this step is the big one. Tables cannot reflow into a single column, so replace them with Flexbox or Grid. Our guide to CSS Flexbox vs Grid explains which to use where.

Step 4: Make images and media scale

Images are a common cause of sideways scrolling. This rule in your stylesheet stops any image from being wider than its container while keeping its proportions:

img, video { max-width: 100%; height: auto; }

Keep the width and height attributes on your <img> tags anyway. Browsers use them to work out the shape of the image and reserve space before it loads, and the CSS above still lets it shrink.

For large photos, you can offer several sizes and let the browser choose the right one with srcset and sizes:

<img src="photo-800.jpg" srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w" sizes="(max-width: 600px) 100vw, 800px" alt="View across the bay" width="800" height="533">

Phones then download a smaller file, which makes pages load faster on mobile connections. Embedded videos and maps from other sites often use fixed sizes too. Giving them width: 100%; and an aspect-ratio such as aspect-ratio: 16 / 9; keeps them in proportion.

Step 5: Adjust the design with media queries

A media query applies CSS only when the screen matches a condition, usually a width. The width where the design changes is called a breakpoint.

A good approach is mobile first: write your basic styles for small screens, then add media queries with min-width to enhance the layout as space grows.

  • .columns { display: grid; gap: 24px; }
  • @media (min-width: 768px) { .columns { grid-template-columns: 1fr 1fr; } }
  • @media (min-width: 1024px) { .columns { grid-template-columns: 1fr 1fr 1fr; } }

Here the columns stack on phones, become two on tablets and three on wider screens.

Choosing breakpoints

Do not chase the exact width of every device. Instead, slowly narrow your browser window and add a breakpoint wherever the design starts to look cramped or broken. Common starting points are below.

BreakpointRoughly coversTypical change
Below 600pxPhonesSingle column, larger tap targets, collapsed menu
600px to 1023pxTablets and small laptopsTwo columns, wider margins
1024px and upLaptops and desktopsFull layout with sidebars or three or more columns

Other things to adjust on small screens

  • Navigation: long menus can wrap onto two lines or move into a toggle menu.
  • Tap targets: buttons and links should be large enough to tap with a finger, with space between them.
  • Text size: body text around 16 pixels is a sensible minimum for reading on a phone.
  • Wide tables: wrap them in a container with overflow-x: auto; so they scroll on their own. See how to make a table in HTML.

Step 6: Test at different sizes

You do not need a drawer full of devices. Most testing can happen on your computer.

  1. Resize your browser window from wide to narrow and watch for overlapping text, sideways scrolling and cut-off images.
  2. Use device mode in your browser's developer tools to view the page at common phone and tablet sizes.
  3. Check both orientations, portrait and landscape.
  4. Try a real phone after publishing, because touch, font rendering and connection speed can feel different.
  5. Zoom the text to 200 percent to check that the layout still holds together.

If something causes a horizontal scrollbar and you cannot find it, look for fixed widths, long unbroken words or URLs, and images or embeds without max-width.

The easier way: preview at desktop, tablet and phone sizes

Responsive design is much easier when you can see every size while you work. Apollo Editor, a Windows desktop HTML editor, is built to help with this.

  • Preview mode shows the page at desktop, tablet and mobile sizes, plus custom sizes, and can open it in your external browser.
  • The CSS Style Designer includes responsive breakpoints and visual controls for Flexbox and Grid.
  • Page Properties sets the viewport for each page, and images get responsive image attributes.
  • 30 original templates are responsive from the start, if you would rather not begin from a blank page.

Everything stays standard HTML and CSS in your own files. See the templates or read about the features.

Frequently asked questions

What makes a website responsive?

A viewport meta tag, layouts that adapt to the screen width, images that scale, and media queries that adjust the design at certain widths.

How do I test my website on a phone without uploading it?

Use an editor or browser with device preview sizes, such as your browser's developer tools, before checking on a real phone after publishing.

What is a breakpoint in CSS?

A screen width at which a media query changes the layout, for example stacking columns on screens narrower than 768 pixels.

Get three guides like this every month, plus software update notices.Subscribe →