Advanced Media Queries
Master advanced CSS media query techniques including container queries, preference queries, and complex conditions.
Advanced media queries enable sophisticated responsive designs based on various device characteristics and user preferences.
Complex Conditions
/* AND condition */
@media (min-width: 768px) and (max-width: 1024px) {
/* Tablet styles */
}
/* OR condition */
@media (max-width: 480px), (min-width: 1200px) {
/* Mobile or large desktop */
}
/* NOT condition */
@media not print {
/* Everything except print */
}User Preference Queries
/* Dark mode */
@media (prefers-color-scheme: dark) {
body {
background-color: #1a1a1a;
color: #ffffff;
}
}
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: #ffffff;
color: #1a1a1a;
}
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
/* High contrast */
@media (prefers-contrast: high) {
.button {
border: 2px solid currentColor;
}
}Device Characteristics
/* Screen resolution */
@media (min-resolution: 2dppx) {
/* Retina displays */
}
/* Orientation */
@media (orientation: portrait) {
/* Portrait mode */
}
@media (orientation: landscape) {
/* Landscape mode */
}
/* Hover capability */
@media (hover: hover) {
.button:hover {
background-color: #0056b3;
}
}
@media (hover: none) {
.button:active {
background-color: #0056b3;
}
}Aspect Ratio
@media (min-aspect-ratio: 16/9) {
/* Wide screens */
}
@media (aspect-ratio: 4/3) {
/* 4:3 screens */
}Range Syntax
/* Modern syntax */
@media (width >= 768px) {
/* Min-width */
}
@media (480px <= width <= 768px) {
/* Between 480px and 768px */
}Best Practices
Media Query Best Practices
- Use mobile-first approach
- Respect user preferences
- Test on real devices
- Consider touch vs hover
- Use logical breakpoints
- Combine multiple conditions
- Provide graceful degradation
Master advanced media queries for sophisticated responsive designs!
How is this guide?
Sign in to share your feedback
Help us improve by sharing your thoughts on this guide.
Last updated on
CSS Masking
Learn CSS masking techniques to clip and shape elements with images and gradients for creative effects.
CSS Tooltips
Learn to create beautiful, accessible tooltips with CSS for providing contextual help and information.
© 2026CoderrShyamAll Rights Reserved.