Media queries let you apply CSS rules based on device characteristics like screen width, height, and orientation. They are essential for responsive design.
Syntax
@media (condition) { CSS rules }
Common Breakpoints
- Mobile — up to 768px
- Tablet — 768px to 1024px
- Desktop — 1024px and up
Mobile-First Approach
Start with styles for mobile devices, then add min-width media queries to enhance for larger screens. This is the recommended approach.
@media (min-width: 768px)— applies when viewport is 768px or wider@media (max-width: 768px)— applies when viewport is 768px or narrower