Smartoolz

HTML Media Queries

CSS Media Queries

Media queries help create responsive websites for different screen sizes.

What are Media Queries?

Media queries allow developers to apply CSS styles based on device characteristics.

They are commonly used for:

Basic Syntax

Example

@media(max-width:768px){

    body{
        background:red;
    }

}

How It Works

The CSS inside the media query runs only when the screen width is 768px or smaller.

Responsive Example

Resize the screen to see the color change.

Responsive Box

Mobile First Design

Mobile-first means designing for mobile devices first, then adding styles for larger screens.

body{
    font-size:14px;
}

@media(min-width:768px){

    body{
        font-size:18px;
    }

}

Common Breakpoints

Device Width
Mobile Up to 768px
Tablet 768px - 992px
Desktop 992px and above

Responsive Flexbox Example

.container{
    display:flex;
}

@media(max-width:768px){

    .container{
        flex-direction:column;
    }

}