Responsive CSS generator • 2026 design tools
\( @media (feature: value) \{ ... \} \)
\( @media screen and (min-width: 768px) \{ ... \} \)
\( @media screen and (max-width: 767px) and (orientation: portrait) \{ ... \} \)
Where:
Media queries allow you to apply CSS rules based on device characteristics like screen size, orientation, or resolution.
Example: A responsive layout:
\( @media screen and (min-width: 768px) \{ \)
\( .container \{ width: 100%; \} \)
\( \} \)
This applies container styles only on screens 768px wide or larger.
Media queries are CSS techniques that allow you to apply different styles based on the characteristics of the device being used to view the content. They are essential for creating responsive websites that adapt to different screen sizes, orientations, and capabilities.
The fundamental syntax for media queries includes:
Where:
Media queries are most effective in these scenarios:
Media type specifies the device category, features query specific characteristics.
\( @media type and (feature: value) \{ ... \} \)
Where type=device category, feature=characteristic, value=threshold.
Choose breakpoints based on content needs, not device specifications.
Which of the following is the correct syntax for a media query targeting screens wider than 768px?
The answer is B) @media screen and (min-width: 768px) { ... }. The correct syntax requires the 'and' keyword between the media type and the media feature. This targets screens that are at least 768px wide.
Understanding media query syntax is fundamental to responsive design. The 'and' operator is crucial when combining a media type with a media feature. Without it, the query won't work correctly. The syntax follows the pattern: @media media-type and (feature: value) { styles }.
Media Query: CSS rule for conditional styling
Media Type: Device category (screen, print, etc.)
Media Feature: Device characteristic (width, height, etc.)
• Use 'and' to combine type and feature
• Parentheses around feature expressions
• Proper syntax is critical for functionality
• Remember: @media type and (feature: value)
• Use min-width for mobile-first approach
• Test queries in browser dev tools
• Forgetting the 'and' keyword
• Missing parentheses around features
• Incorrect operator usage
What does this media query target: @media screen and (min-width: 768px) and (max-width: 1023px)?
This media query targets screens that are at least 768px wide but no more than 1023px wide. This is commonly used for tablets in landscape mode or small laptops. The 'and' operator means both conditions must be true simultaneously.
Range: 768px ≤ screen width ≤ 1023px
Devices: Primarily tablets in landscape orientation or small laptops.
Multiple conditions in a media query are joined with 'and', meaning all conditions must be satisfied. This creates a range between two values. The min-width ensures the screen is at least 768px, while max-width ensures it's no more than 1023px, creating a specific window for intermediate-sized devices.
Range Query: Targets specific range of values
Logical AND: All conditions must be true
Breakpoint Range: Specific device category
• 'and' means all conditions must be true
• Range queries define specific device categories
• Order of conditions doesn't matter
• Combine min and max for ranges
• Use for intermediate device sizes
• Test actual device widths
• Confusing 'and' with 'or' logic
• Overlapping breakpoint ranges
• Not considering device orientation
A web developer wants to create a responsive layout where a sidebar is visible on desktop (≥1024px) but hidden on mobile (≤767px). They want the main content to take full width on mobile but 70% width on desktop. Write the appropriate media queries for this layout.
Mobile-first approach:
This approach starts with mobile styles as defaults and adds desktop enhancements.
The mobile-first approach is recommended because it follows the progressive enhancement principle. Start with the simplest version (mobile) and add complexity for larger screens. This ensures good performance on mobile devices and creates a logical flow of enhancements.
Mobile First: Start with mobile styles
Progressive Enhancement: Add features for capable devices
Default Styles: Base styles for smallest screens
• Mobile styles are defaults
• Desktop queries add enhancements
• Use min-width for mobile-first
• Use min-width for upward breakpoints
• Test with browser dev tools
• Consider content-based breakpoints
• Desktop-first approach causing bloat
• Not testing mobile performance
• Device-specific rather than content-based
A designer wants to adjust a mobile app interface based on device orientation. When in portrait mode, the navigation should be at the bottom. When in landscape mode, it should move to the side. Write media queries to handle this, assuming the navigation has class 'nav'.
This targets orientation while considering screen height to avoid affecting desktop.
Orientation queries are powerful for mobile-specific layouts. However, they can also affect desktop browsers when resized. Adding a height constraint ensures the landscape styles only apply to mobile devices. This demonstrates the importance of considering multiple features in media queries.
Orientation: Device rotation (portrait/landscape)
Multi-Feature Query: Uses multiple conditions
Constraint Logic: Additional conditions for precision
• Orientation affects mobile primarily
• Add constraints to avoid desktop conflicts
• Test on actual mobile devices
• Combine orientation with size constraints
• Consider touch vs mouse interactions
• Test both orientations thoroughly
• Not constraining orientation queries
• Assuming all mobile devices are the same
• Ignoring touch interface differences
Which of the following represents the best practice for creating responsive breakpoints?
The answer is B) Use content-based breakpoints. Content-based breakpoints focus on when the layout breaks rather than specific device sizes. This approach is more future-proof and adaptable to new devices. Instead of targeting specific devices, you adjust the layout when content no longer fits well at a particular size.
Content-based breakpoints are superior to device-specific ones because there are countless device sizes in the market. By focusing on when the content layout becomes problematic, you create a more robust responsive system. This approach ensures your design works on current and future devices without requiring constant updates.
Content-Based: Breakpoints determined by content needs
Device-Specific: Breakpoints for particular devices
Future-Proof: Works with new devices
• Break when content no longer fits well
• Focus on user experience over device specs
• Test with real content
• Resize browser to find natural breaks
• Use real content for testing
• Consider typography and spacing
• Targeting specific devices instead of content
• Using too many breakpoints
• Not testing with real content
Q: What's the difference between min-width and max-width in media queries?
A: The difference is:
Example: @media (min-width: 768px) targets screens 768px and wider, while @media (max-width: 767px) targets screens 767px and narrower.
Mathematically: min-width ≥ value, max-width ≤ value.
Q: Should I use mobile-first or desktop-first approach for media queries?
A: Mobile-first is generally recommended because:
Use min-width for breakpoints when going mobile-first, which progressively enhances the layout for larger screens.