CSS Media Queries Breakpoints for Responsive Web Design

Faraz Logo

By Faraz - Last Updated:

Discover all CSS media query breakpoints for responsive web design in one place. Easily adjust styles for mobile, tablet, desktop, and retina screens.


css-media-queries-breakpoints-for-responsive-web-design.webp

Responsive web design is essential for modern websites. With people using different devices like mobile phones, tablets, laptops, and large desktops, it's important to provide a smooth experience on all screen sizes. CSS media queries make this possible by letting developers adjust styles based on the device's screen size, orientation, and pixel density.

In this guide, we'll cover different breakpoints for responsive design, focusing on mobile devices, tablets, laptops, desktops, and high-resolution displays.

What Are Media Queries?

Media queries are a CSS3 feature that allows you to apply CSS styles conditionally. These styles can adapt to the user’s screen size, resolution, or orientation, ensuring your website looks great on any device. By using breakpoints, which are the specific conditions you set for the media queries, you can design responsive layouts that work across a range of devices.

Basic Structure of a Media Query

Before we dive into the different sizes, let's look at the basic structure of a media query. It usually looks something like this:

@media only screen and (max-width: 768px) {
/* CSS styles for devices with a width of 768px or less */
}

In this example:

  • @media tells the browser that this is a media query.
  • only screen is a filter that applies styles only to screen-based devices (ignores print).
  • (max-width: 768px) means that the styles inside this block will be applied only when the device's screen is 768 pixels or smaller.

In the example above, the styles will apply only if the screen width is 768px or less. You can use max-width for small screens or min-width for larger screens, depending on your needs.

Now, let’s break down the most commonly used media query breakpoints.

1. Media Queries for Mobile Devices

Mobile devices vary greatly in size. It’s important to cater to both portrait and landscape orientations. Here are the most common breakpoints for mobile:

Extra Small Devices (Phones in Portrait Mode)

For very small mobile devices, such as older phones, you can use the following media query:

@media only screen and (max-width: 320px) {
  /* Styles for extra small mobile devices */
}

This applies to devices with a width of 320px or less, like the iPhone SE or earlier Android phones.

Small Devices (Phones in Landscape Mode)

To cover mobile phones in landscape mode, you can increase the maximum width:

@media only screen and (max-width: 480px) {
  /* Styles for small devices in landscape */
}

This applies to devices with a width of 480px or less, such as when the iPhone SE or earlier Android phones are used in landscape mode.

Medium Devices (Phones and Small Tablets)

For slightly larger phones and small tablets in portrait mode, use this breakpoint:

@media only screen and (max-width: 576px) {
  /* Styles for medium mobile devices */
}

This applies to devices with a width of 576px or less, like larger smartphones and smaller tablets such as the iPhone or Google Pixel.

2. Media Queries for Tablets and Small Desktops

As you move to larger devices like tablets and small desktops, it’s crucial to adjust your layout to make use of the extra screen space.

Small Tablets (Portrait Mode)

For small tablets in portrait orientation, this breakpoint is useful:

@media only screen and (max-width: 768px) {
  /* Styles for small tablets */
}

This applies to devices with a width of 768px or less, like the iPad Mini in portrait mode.

Tablets (Landscape Mode)

When tablets are used in landscape mode, they often have more width available. For this, you can use:

@media only screen and (max-width: 992px) {
  /* Styles for tablets in landscape mode */
}

This applies to devices with a width of 992px or less, such as the iPad or iPad Air in landscape mode.

3. Media Queries for Laptops and Desktops

Laptops and desktops vary in screen size, and the breakpoints need to be adjusted accordingly.

Small Laptops and Large Tablets

For smaller laptops and larger tablets, this breakpoint will work:

@media only screen and (max-width: 1200px) {
  /* Styles for small laptops and large tablets */
}

This applies to devices with a width of 1200px or less, like a 13-inch MacBook Pro or large tablets like the iPad Pro.

Standard Desktops

For most desktop screens, you can use:

@media only screen and (max-width: 1400px) {
  /* Styles for standard desktops */
}

This applies to devices with a width of 1400px or less, which covers a variety of desktop monitors commonly used in workplaces or homes.

Large Desktops

If your users are accessing your site on larger desktop screens, you may need to make adjustments using this query:

@media only screen and (max-width: 1600px) {
  /* Styles for large desktops */
}

This applies to devices with a width of 1600px or less, such as large desktop monitors used for gaming or design work.

4. Media Queries for Extra Large Screens

For extra-large screens, you can set a minimum width to make sure that the layout takes advantage of the wide screen:

@media only screen and (min-width: 1601px) {
  /* Styles for extra-large screens */
}

This applies to devices with a width of 1601px or more, like ultra-wide desktop monitors or high-end display setups.

5. Orientation-Specific Media Queries

In addition to breakpoints for screen width, you can also use media queries to target devices based on their orientation. This is helpful when a user rotates their phone or tablet.

Portrait Mode

To apply styles when the device is in portrait orientation:

@media only screen and (orientation: portrait) {
  /* Styles for portrait mode */
}

This applies to devices like phones and tablets when held in portrait mode, which is common for reading and browsing.

Landscape Mode

For landscape orientation, use this query:

@media only screen and (orientation: landscape) {
  /* Styles for landscape mode */
}

This applies to devices like phones and tablets when held in landscape mode, often used for watching videos or playing games.

6. Media Queries for Retina Displays

Retina displays have a higher pixel density, so it’s important to provide high-resolution graphics and styling. You can use media queries to target these devices:

@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (min-resolution: 192dpi) {
  /* Styles for retina displays */
}

This applies to devices like iPhones, MacBooks, and other high-resolution screens, ensuring that images and text appear sharp.

Default Breakpoints for Popular Devices

Some standard breakpoints for responsive design include:

Breakpoint Identifier Media Query Maximum Width Breakpoint
Extra Small Devices (Portrait) @media only screen and (max-width: 320px) 320px
Small Devices (Landscape) @media only screen and (max-width: 480px) 480px
Medium Devices (Phones & Tablets) @media only screen and (max-width: 576px) 576px
Small Tablets (Portrait) @media only screen and (max-width: 768px) 768px
Tablets (Landscape) @media only screen and (max-width: 992px) 992px
Small Laptops and Large Tablets @media only screen and (max-width: 1200px) 1200px
Standard Desktops @media only screen and (max-width: 1400px) 1400px
Large Desktops @media only screen and (max-width: 1600px) 1600px
Extra-Large Screens @media only screen and (min-width: 1601px) No max-width (infinite)
Portrait Mode @media only screen and (orientation: portrait) None (based on orientation)
Landscape Mode @media only screen and (orientation: landscape) None (based on orientation)
Retina Displays @media only screen and (min-resolution: 192dpi) None (based on resolution)

How to Implement Media Queries in CSS

To implement a media query in CSS, you use the @media rule followed by conditions, such as screen width, to specify when the styles should apply. Here’s a simple example of a media query:

@media (max-width: 768px) {
  body {
    background-color: lightblue;
  }
}

In this case, if the screen is 768px wide or smaller, the background color will change to light blue.

Using Min-Width and Max-Width in Breakpoints

There are two main approaches when setting breakpoints: min-width and max-width.

Min-Width Approach

The min-width approach applies styles when the screen width is greater than a certain size. This is often referred to as a "mobile-first" approach, where you design for smaller screens and scale up.

@media (min-width: 768px) {
  .container {
    width: 80%;
  }
}

Max-Width Approach

The max-width approach applies styles when the screen width is less than a certain size. It is often used when designs start from a desktop version and then scale down.

@media (max-width: 768px) {
  .container {
    width: 100%;
  }
}

Common Mistakes to Avoid with Media Queries

  • Setting too many breakpoints: Only define the necessary ones to keep code clean.
  • Ignoring landscape/portrait differences: Ensure your design adapts to both.
  • Forgetting about touch events: On smaller devices, prioritize touch functionality.

Tools to Test Media Queries Responsiveness

Several tools are available to test how your breakpoints behave:

Conclusion

By using CSS media queries and breakpoints, you can ensure that your website is responsive across all devices. Whether your users are on mobile phones, tablets, laptops, desktops, or retina displays, your website will look great and perform well. Understanding the right breakpoints for each device type is key to delivering a seamless user experience.

Make sure to test your designs on various devices and orientations to ensure a smooth and responsive experience for all users.

Summary of Common Breakpoints:

1. Mobile Devices (Portrait and Landscape)
/* Extra small devices (phones, portrait) */
@media only screen and (max-width: 320px) {
  /* Styles for small mobile devices */
}

/* Small devices (phones, landscape) */
@media only screen and (max-width: 480px) {
  /* Styles for medium mobile devices */
}

/* Medium devices (phones, portrait and small tablets) */
@media only screen and (max-width: 576px) {
  /* Styles for larger mobile devices */
}

2. Tablets and Small Desktops
/* Small tablets (portrait) */
@media only screen and (max-width: 768px) {
  /* Styles for tablets in portrait mode */
}

/* Tablets (landscape) */
@media only screen and (max-width: 992px) {
  /* Styles for tablets in landscape mode */
}

3. Laptops and Desktops
/* Small laptops and large tablets */
@media only screen and (max-width: 1200px) {
  /* Styles for small laptops and large tablets */
}

/* Desktops */
@media only screen and (max-width: 1400px) {
  /* Styles for standard desktops */
}

/* Large desktops */
@media only screen and (max-width: 1600px) {
  /* Styles for large desktops */
}

4. Extra Large Screens
/* Extra large screens */
@media only screen and (min-width: 1601px) {
  /* Styles for extra-large screens */
}

5. Orientation-Specific Media Queries
/* Portrait mode */
@media only screen and (orientation: portrait) {
  /* Styles for portrait mode */
}

/* Landscape mode */
@media only screen and (orientation: landscape) {
  /* Styles for landscape mode */
}

6. Retina Displays
/* Retina displays */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (min-resolution: 192dpi) {
  /* Styles for retina displays */
}

Use these breakpoints to guide your responsive design strategy and ensure that your site works beautifully on any device.

That’s a wrap!

Thank you for taking the time to read this article! I hope you found it informative and enjoyable. If you did, please consider sharing it with your friends and followers. Your support helps me continue creating content like this.

Stay updated with our latest content by signing up for our email newsletter! Be the first to know about new articles and exciting updates directly in your inbox. Don't miss out—subscribe today!

If you'd like to support my work directly, you can buy me a coffee . Your generosity is greatly appreciated and helps me keep bringing you high-quality articles.

Thanks!
Faraz 😊

End of the article

Subscribe to my Newsletter

Get the latest posts delivered right to your inbox


Latest Post