CSS @media Rule (original) (raw)

Last Updated : 8 Jun, 2026

The @media CSS at-rule applies styles based on device characteristics like width, height, resolution, or orientation, enabling responsive and optimized designs.

**Syntax:

@media not|only mediatype and (media feature and|or|not mediafeature)
{
// CSS Property
}

Used Keywords

Media query keywords like not, only, and and help control how and when CSS rules are applied based on device types or features.

Media types specify which devices or media the CSS rules should target, allowing tailored styles for different outputs.

There are many media features in Media Query some of them are listed below:

**Example: The @media rule applies styles only when the specified media query matches the device’s characteristics.

HTML `

CSS @media rule
<style>
    @media screen and (max-width: 600px) {

        h1,
        h2 {
            color: green;
            font-size: 25px;
        }

        p {
            background-color: green;
            color: white;
        }
    }
</style>

GeeksforGeeks

CSS @media rule

GeeksforGeeks: A computer science portal

`

**Output: From the output, we can see when screen width resizes less than or equal to 600px then the text color also changes to green.