CSS Media Queries

What are Media Queries?

Media queries allow you to apply styles based on screen size or device conditions.

They are used to make websites responsive across phones, tablets, and desktops.

Loading...
Output:

Breakpoints

Breakpoints define where your layout changes for different screen sizes.

  • 1200px → large screens
  • 992px → laptops
  • 768px → tablets
  • 576px → phones

Max-Width

Applies styles when the screen width is less than or equal to a value.

Loading...
Output:

Min-Width

Applies styles when the screen width is greater than or equal to a value.

Loading...
Output:

Mobile-First Design

Start with styles for small screens, then scale up using min-width.

Loading...
Output:

Responsive Grid Example

Loading...
Output:

Combining Conditions

You can combine conditions using and.

Loading...
Output:

Full Example

Loading...
Output:

Why Media Queries are Important

  • Make websites responsive
  • Improve user experience
  • Essential for modern web design

Common Mistakes

  • Using too many breakpoints
  • Not using mobile-first design
  • Forgetting units like px
  • Overwriting styles incorrectly

Practice

Create a layout that changes from 1 column to 2 columns to 3 columns using media queries.

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic