Skip to main content

Command Palette

Search for a command to run...

Responsive Design & Media Queries in CSS

Updated
4 min readView as Markdown

Over the past few days, I've learned how to build layouts using Flexbox and CSS Grid.

Today, I explored one of the most important concepts in modern web development—Responsive Design.

A website should look good not only on a desktop but also on tablets, laptops, and smartphones.

Responsive Design makes that possible.

Let's dive in.


What is Responsive Design?

Responsive Design is an approach to web development where a website automatically adjusts its layout, images, and content based on the screen size and device being used.

Instead of creating separate websites for desktop and mobile, we create one website that adapts to different screen sizes.


Why is Responsive Design Important?

Today, users browse websites on many different devices:

  • 📱 Smartphones

  • 📲 Tablets

  • 💻 Laptops

  • 🖥️ Desktop Computers

  • 📺 Smart TVs

A responsive website provides a consistent and user-friendly experience across all of them.

Benefits include:

  • Better User Experience

  • Mobile-Friendly Design

  • Improved SEO

  • Easier Maintenance

  • Faster Development


The Viewport Meta Tag

Every responsive webpage should include the viewport meta tag.

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

This tells the browser to match the page width to the device's screen width.

Without it, responsive layouts may not work as expected on mobile devices.


What are Media Queries?

Media Queries allow us to apply different CSS rules depending on the screen size.

Basic syntax:

@media (max-width:768px){

    body{

        background:lightblue;

    }

}

If the screen width is 768px or smaller, the CSS inside the media query will be applied.


Common Breakpoints

Although breakpoints vary depending on the project, these are commonly used:

Device Width
Mobile 480px – 767px
Tablet 768px – 1023px
Laptop 1024px – 1439px
Desktop 1440px and above

These are guidelines, not strict rules.


Max-Width vs Min-Width

Max-Width

@media (max-width:768px){

}

Applies styles up to 768px.


Min-Width

@media (min-width:768px){

}

Applies styles from 768px and larger.

Both approaches are widely used depending on the design strategy.


Mobile-First Design

Modern developers usually follow the Mobile-First approach.

This means:

  1. Design for small screens first.

  2. Gradually enhance the layout for larger screens using min-width media queries.

This often leads to cleaner and more maintainable CSS.


Responsive Images

To make images responsive:

img{

    max-width:100%;

    height:auto;

}

This ensures images never overflow their container while maintaining their aspect ratio.


Responsive Layout with Flexbox

.container{

    display:flex;

    flex-wrap:wrap;

}

Using flex-wrap allows items to move to the next line when space becomes limited.


Responsive Grid

CSS Grid also makes responsive layouts easy.

.container{

grid-template-columns:

repeat(auto-fit,minmax(250px,1fr));

}

The browser automatically adjusts the number of columns based on the available space.


Best Practices

✔ Start with a Mobile-First approach.

✔ Use relative units like %, rem, vw, and vh.

✔ Make images responsive.

✔ Test layouts on multiple screen sizes.

✔ Combine Flexbox and Grid for modern responsive designs.


My Biggest Takeaway

Before today, I thought responsiveness meant shrinking a webpage.

Now I understand it's about creating layouts that adapt intelligently to different devices.

Media Queries, responsive units, Flexbox, and Grid all work together to make websites look great on any screen.

This is one of the most practical skills I've learned so far because every modern website needs to be responsive.

100 Days of Code: My Journey to Becoming a Full Stack Developer

Part 28 of 50

Welcome to my 100 Days of Code journey! In this series, I'll document my daily progress as I learn Full Stack Web Development from the ground up. Every post will cover what I learned, challenges I faced, mistakes I made, and the projects I built. My goal is not just to complete 100 days but to become a better developer through consistency, discipline, and learning in public. Topics I'll cover include: • Git & GitHub • HTML, CSS & JavaScript • React.js • Node.js & Express • MongoDB • APIs • Real-world Projects • AI tools for Developers Whether you're just starting out or revising your fundamentals, I hope this journey helps you learn alongside me. Let's build, learn, and grow together! 🚀

Up next

CSS Transitions & Animations – Bringing Websites to Life

Over the past few days, I've learned how to create responsive layouts using Flexbox, Grid, and Media Queries. Today, I explored how to make websites more interactive and visually engaging with CSS Tra

More from this blog

T

TheSaurceCode

73 posts

Documenting my journey to becoming a Full Stack Developer through daily blogs, coding challenges, projects, tutorials, and lessons learned. Learn, build, and grow with me