# Media Query

Media Queries are conditional statements in CSS that let you apply style based on specific media features like screen size, device type and orientation or resolution. They are responsible for creating responsive websites with respect to different devices.

**Layman's Explanation**

Imagine your website as a chameleon adapting its appearance based on the platform it's on. Media Queries are like its magic chameleon skin. They let you tell the website "Hey if you are using a phone, shrink the font size for easier reading " or if its big screen show different view.

Example:

```xml
<!DOCTYPE html>
<html>

<head>
    <title>Responsive Website Example</title>
    <link rel="stylesheet" href="../CSS/style.css">
</head>

<body>

    <header>
        <h1>My Responsive Website</h1>
    </header>

    <main class="content">
        <article>
            <h2>Article 1</h2>
            <p>This is Article One.</p>
        </article>
        <article>
            <h2>Article 2</h2>
            <p>This is Article Two.</p>
        </article>
    </main>

</body>

</html>
```

```css

body {

    margin: 0;
}

header {
    background-color: orange;
    padding: 20px;
}

.content {
    margin: 20px;
}

article {
    margin-bottom: 20px;
    border: 1px solid #ccc;
    padding: 10px;
}


@media screen and (max-width: 600px) {
    .content {
        width: 100%;
        /* Full width on small screens */
    }

    article {
        display: block;
       
    }
}

@media screen and (min-width: 601px) and (max-width: 900px) {
    .content {
        display: flex;
        /* on medium screens */
        flex-wrap: wrap;
    }

    article {
        width: 50%;
        
    }
}

@media screen and (min-width: 901px) {
    .content {
        display: flex;
        /* wider spacing on large screens */
        justify-content: space-between;
    }

    article {
        width: 45%;
        /* Adjust for spacing */
    }
}
```

Output:

Full Screen

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706679018111/c677636a-8596-40b5-9cc7-369d2ffdd85c.png align="center")

Medium Size

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706679077828/afd71f95-8797-4d7e-a335-69b96dc20190.png align="center")

Small Size

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706679141890/2f94e64f-b63a-419c-b3ea-445213fd3b1c.png align="center")

The output is slightly varied based on the width of the screens sizes.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706680334176/491eb9e7-5d2a-437b-8e0b-44cc20a1e9ad.gif align="center")
