Cartoon portrait of Athul in a striped shirt; his eyes follow your cursor

← All articles

Web Development

How to Make a Website Responsive on Every Screen

Learn how to build responsive websites for mobile, tablet, and desktop.

  • Web Development
  • CSS
  • Responsive Design
  • Frontend Development
A website shown responsively on a phone, a tablet and a laptop, with the title “How to Make a Website Responsive on Every Screen”.

Introduction

A website can look impressive on a desktop computer but become difficult to use on a mobile phone. Text may overflow, buttons may become too small, images may extend beyond the screen, and navigation menus may stop working correctly. These problems can frustrate visitors and make an otherwise professional website feel unfinished.

Responsive web design solves this problem by allowing a website's layout and content to adapt to different screen sizes. Whether someone visits from a smartphone, tablet, laptop, or large desktop monitor, the website should remain readable, functional, and visually consistent.

Today, responsive design is an essential part of modern web development. People access websites using a wide variety of devices, and developers cannot assume that every visitor has the same screen dimensions or browsing experience.

In this guide, you will learn how to make a website responsive using practical CSS techniques, mobile-first development, flexible layouts, responsive images, and real-device testing.

What Is Responsive Web Design?

Responsive web design is an approach to building websites that automatically adjust their layout according to the available screen space.

A responsive website does not require a separate website for every device. Instead, it uses flexible layouts and CSS rules to reorganize content when the viewport changes.

For example, a desktop page might display three project cards in one row. On a tablet, those cards could appear in two columns, while on a mobile phone, they might stack vertically.

Responsive design typically combines three techniques:

  • Flexible layouts: Elements resize or rearrange according to available space.
  • Media queries: CSS rules apply different styles at selected viewport widths.
  • Flexible media: Images and videos scale without overflowing their containers.

The objective is not simply to make everything smaller. It is to preserve usability and hierarchy across different devices.

1. Start With a Mobile-First Approach

One of the most effective ways to create a responsive website is to design for mobile screens first.

A mobile-first approach means writing the initial CSS for smaller screens and then adding enhancements for tablets and desktops. This encourages developers to prioritize essential content and avoid unnecessary complexity.

For example, begin with a single-column layout:

.container {
  width: 100%;
  padding: 1rem;
}

.project-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

The project cards appear in one column, making them easy to read on smaller screens.

You can then introduce additional columns when more space is available:

@media (min-width: 768px) {
  .container {
    padding: 2rem;
  }

  .project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .project-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

This approach is useful for portfolios, blogs, product pages, and business websites.

Why mobile-first design works

Starting small helps you identify the most important information before adding decorative elements. It also makes it easier to establish a clear reading order, create accessible buttons, and prevent content from becoming cramped.

However, mobile-first does not mean ignoring desktop users. The layout should still take advantage of larger screens through better spacing, wider content areas, and more sophisticated compositions.

2. Use the Viewport Meta Tag

A responsive layout may not behave correctly on mobile devices if the HTML document does not include the appropriate viewport setting.

Add this line inside the document's <head> element:

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

The width=device-width setting tells the browser to use the device's viewport width as the layout width. initial-scale=1 establishes the initial zoom level.

Without this configuration, some mobile browsers may render a page using a wider virtual viewport and scale it down. As a result, text and interactive elements can appear unnecessarily small.

In a Next.js application using the App Router, viewport configuration can also be managed through the framework's supported viewport export where appropriate.

Remember that the viewport tag is only the starting point. Your CSS must still define flexible layouts, appropriate typography, and responsive components.

3. Build Flexible Layouts With CSS Flexbox

CSS Flexbox is useful when elements need to align horizontally or vertically and distribute the available space.

It works particularly well for navigation bars, hero sections, button groups, and card content.

For example:

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.hero-content,
.hero-image {
  flex: 1 1 0;
  min-width: 0;
}

@media (max-width: 700px) {
  .hero {
    flex-direction: column;
    align-items: stretch;
  }
}

On wider screens, the text and image can sit beside each other. On smaller screens, they stack vertically.

The min-width: 0 declaration is important in certain flex layouts because it allows a flex child to shrink below its content's intrinsic width. Without it, long text or other content can cause overflow.

Avoid fixed widths

A common mistake is assigning large fixed widths to elements:

/* Less flexible */
.hero-content {
  width: 650px;
}

That width may be appropriate on a desktop but too wide on a phone.

A more adaptable option is:

.hero-content {
  width: 100%;
  max-width: 650px;
}

The element can shrink to fit its parent while maintaining a maximum width on larger screens.

4. Use CSS Grid for Responsive Layouts

CSS Grid is especially useful for project galleries, service sections, article listings, and image collections.

You can create a grid that automatically adjusts the number of columns based on the available width:

.project-grid {
  display: grid;
  grid-template-columns:
    repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 1.5rem;
}

This layout allows cards to fit into as many columns as the available space permits, while attempting to keep each card around 260 pixels or wider.

The min(100%, 260px) expression prevents the minimum track size from exceeding the container width on narrow screens.

Grid is useful when you want the browser to handle much of the layout adjustment without creating a separate media query for every possible screen size.

Choosing between Flexbox and Grid

Use Flexbox when the primary goal is to arrange items along one dimension, such as a row of navigation links.

Use Grid when you need to control both rows and columns, such as a gallery of portfolio projects.

They are complementary technologies, so a website can use both.

5. Make Images and Videos Responsive

Large images can create horizontal scrolling or distort the layout if their dimensions are not constrained.

A useful default is:

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

This allows images to shrink within their containers while preserving their intrinsic aspect ratio.

For project thumbnails that should have a consistent shape, use object-fit:

.project-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

The image fills the designated area without becoming stretched. Some of its edges may be cropped, so choose source images that work well with the intended aspect ratio.

Use appropriately sized images

A responsive image is not necessarily an optimized image. Sending a very large desktop photograph to every mobile visitor can waste bandwidth.

Use modern image formats where suitable, provide correctly sized variants, and consider the HTML srcset and sizes attributes or your framework's image optimization features.

For example:

<img
  src="project-800.jpg"
  srcset="
    project-400.jpg 400w,
    project-800.jpg 800w,
    project-1200.jpg 1200w
  "
  sizes="(max-width: 600px) 100vw, 50vw"
  alt="Screenshot of a responsive website project"
/>

The browser can select a suitable image candidate based on the available layout width and device characteristics.

Always provide meaningful alternative text when an image conveys information. Decorative images can use an empty alt attribute.

6. Make Typography Adapt to Screen Size

Text that looks balanced on a desktop may appear oversized on a phone or too small on a large monitor.

Instead of defining a different font size for every device, use CSS clamp() for fluid typography:

.hero-title {
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 1.1;
}

The first value sets a minimum size, the middle value provides a fluid preference, and the last value sets the maximum size.

This allows the heading to scale gradually rather than jumping between fixed sizes.

Also consider line length. A paragraph that stretches across a very wide monitor can become difficult to read. Set a maximum width:

.article-content {
  max-width: 70ch;
  line-height: 1.75;
}

The ch unit is based on the width of the zero character in the element's font. It is a useful approximation for controlling text measure.

Maintain adequate contrast, comfortable line spacing, and enough separation between headings and paragraphs.

7. Create a Responsive Navigation Menu

Navigation is one of the most visible parts of responsive design.

A desktop navigation bar might contain several links arranged in a row. On a mobile device, those links can become cramped or wrap onto multiple lines.

A common solution is to use a compact menu on smaller screens.

The exact implementation depends on your framework, but the design should include:

  • A clearly labelled menu button.
  • A visible open and closed state.
  • Keyboard-accessible interaction.
  • A sensible focus order.
  • Adequate spacing between links.
  • An understandable way to close the menu.

If you build the menu with JavaScript or React, ensure that the button's aria-expanded state reflects whether the menu is open. The menu should work with a keyboard as well as a touchscreen.

Do not hide essential navigation behind a menu on every device by default. On wider screens, a horizontal navigation bar may provide a better experience.

8. Choose Breakpoints Based on Content

A breakpoint is a viewport width at which a media query changes the layout.

There is no single set of breakpoints that works perfectly for every website. A better approach is to observe when your content starts to feel crowded or becomes difficult to use.

For example:

/* Base styles: narrow screens */

@media (min-width: 640px) {
  /* Wider mobile screens and small tablets */
}

@media (min-width: 768px) {
  /* Tablet and medium layouts */
}

@media (min-width: 1024px) {
  /* Desktop layouts */
}

@media (min-width: 1280px) {
  /* Large desktop enhancements */
}

These are starting points, not strict rules.

If a navigation bar breaks at 900 pixels, create a breakpoint that addresses that problem. If a card layout works comfortably at 720 pixels, there may be no need to change it at 768 pixels.

The goal is to support the content, not a list of device models.

9. Prevent Horizontal Overflow

Horizontal scrolling is a common sign of a responsive layout problem.

Typical causes include fixed-width elements, oversized images, long URLs, large code blocks, and flex children that refuse to shrink.

Use browser developer tools to inspect the element extending beyond the viewport.

For example, long text can be handled with:

.text-content {
  overflow-wrap: anywhere;
}

For code examples, a scrolling container may be more appropriate:

.code-container {
  max-width: 100%;
  overflow-x: auto;
}

Avoid applying overflow-x: hidden to the entire page as a quick fix without identifying the underlying issue. It may hide content that visitors should be able to access.

Also use flexible spacing and widths rather than relying on large fixed margins that only work on desktop.

10. Test the Website on Different Screens

A website that looks correct in your development environment may still fail on real devices.

Use browser developer tools to test common viewport sizes, rotate mobile devices, and inspect both portrait and landscape orientations.

Test more than the homepage. Review article pages, contact forms, project galleries, navigation menus, buttons, and any interactive components.

Check the following:

  • Does the page fit the viewport without unintended horizontal scrolling?
  • Can visitors read the text without zooming in?
  • Are buttons large enough to tap comfortably?
  • Do images maintain their proportions?
  • Does navigation remain usable?
  • Do forms display labels and validation messages correctly?
  • Are focus indicators visible when navigating with a keyboard?
  • Do long headings and URLs wrap appropriately?

Browser emulation is useful, but it does not perfectly reproduce every real-device condition. Test on physical phones and tablets when possible.

Common Responsive Design Mistakes

Avoid these frequent problems:

Using fixed widths everywhere. Fixed dimensions can make layouts overflow. Prefer flexible widths and maximum-width constraints.

Designing only for popular devices. Visitors may use unusual screen dimensions, zoom settings, or browser windows. Flexible layouts are more robust than device-specific assumptions.

Making everything tiny on mobile. Responsive design should preserve readability and touch usability, not simply shrink desktop content.

Ignoring accessibility. Small text, low contrast, keyboard traps, and inaccessible menus can make a responsive website difficult to use.

Using too many breakpoints. Excessive media queries can create conflicting styles. Start with a simple layout and introduce breakpoints only when needed.

Testing only the homepage. Every route and reusable component needs appropriate responsive behavior.

Frequently Asked Questions

What is the easiest way to make a website responsive?

Start with the viewport meta tag, flexible widths, responsive images, and a mobile-first layout. Use CSS Grid or Flexbox for flexible arrangements, then add media queries when the content needs to change.

Is CSS Grid better than Flexbox for responsive design?

Neither is universally better. Flexbox is useful for one-dimensional layouts, while Grid is well suited to two-dimensional arrangements. Most websites benefit from using both.

How many responsive breakpoints should a website have?

There is no required number. Use as few as necessary to keep the layout usable. Breakpoints should respond to content needs rather than a fixed list of devices.

Can a website be responsive without JavaScript?

Yes. Core responsive behavior can be implemented using HTML and CSS alone. JavaScript may be necessary for interactive features such as an expandable mobile menu, but it is not required for basic responsive layouts.

Does responsive design improve SEO?

Responsive design helps search engines and visitors access the same content across devices. It can also support better usability. However, responsiveness alone does not guarantee higher rankings; content quality, performance, accessibility, and other factors matter too.

Conclusion

Making a website responsive involves more than adjusting a few CSS values. It requires flexible layouts, appropriate typography, responsive media, accessible navigation, and consistent testing.

Start with mobile-first CSS, use Grid and Flexbox where they fit, avoid unnecessary fixed widths, and test your pages at different viewport sizes. Pay particular attention to real content, because long headings, project images, and interactive components often reveal problems that simple placeholder layouts do not.

Whether you are creating a personal portfolio, a business website, or a complex web application, responsive design helps deliver a more reliable experience to visitors on the devices they already use.