Careeroza
Media Queries
The @media Rule
Media queries apply CSS only when a condition is true, most often the viewport width:
@media (max-width: 600px) {
/* rules for screens 600px wide or smaller */
}
@media (min-width: 768px) and (max-width: 1023px) { ... } /* tablets */
@media (prefers-color-scheme: dark) { ... } /* user prefers dark mode */
@media print { ... } /* when printing */Example
Example
Two columns on wide screens, one column below 500px. Run it and drag the divider in the code runner:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
.row { display: flex; gap: 10px; font-family: Arial; }
.col { flex: 1; padding: 16px; color: white; }
.left { background: #1971c2; }
.right { background: #04AA6D; }
@media (max-width: 500px) {
.row { flex-direction: column; }
}
</style>
</head>
<body>
<div class="row">
<div class="col left">Left column</div>
<div class="col right">Right column</div>
</div>
</body>
</html>Result
Common Breakpoints
| Breakpoint | Devices |
|---|---|
| up to 599px | phones |
| 600px – 1023px | tablets, small laptops |
| 1024px and up | laptops and desktops |
Tip: Choose breakpoints where your layout starts to look bad, not for specific devices.