Questions
22 of 33
1What is a breakpoint in CSS? Why are breakpoints used in responsive web design?
2What is the syntax for setting a breakpoint using a media query?
3What is the syntax for setting a breakpoint using a media query?
4What units are typically used for defining breakpoints (e.g., px, em, rem)?
5What happens if no breakpoints are defined in a responsive layout?
6How do breakpoints help in mobile-first design?
7How does CSS decide which breakpoint to apply when multiple match?
8What’s the difference between min-width and max-width in media queries?
9How can you create a layout that adjusts between two breakpoints?
10What is the difference between device-based breakpoints and content-based breakpoints?
11What is the role of the viewport meta tag in responsive design?
12How do breakpoints help in mobile-first design?
13How does CSS decide which breakpoint to apply when multiple match?
14What’s the difference between min-width and max-width in media queries?
15What is the difference between device-based breakpoints and content-based breakpoints?
16What is the role of the viewport meta tag in responsive design?
17What is the difference between using em and px in defining breakpoints?
18How do you handle overlapping or conflicting breakpoint rules?
19Can breakpoints be combined with CSS Grid or Flexbox?
20How do CSS container queries differ from traditional breakpoints?
21How can you implement responsive typography using breakpoints?
22How can you use logical operators (and, not, only) in media queries?
23How does pixel density (device-pixel-ratio) affect breakpoints?
24What is the difference between min-device-width and min-width?
25How do you use breakpoints in frameworks like Bootstrap or Tailwind CSS?
26How would you write a media query for screens smaller than 768px?
27How would you create a responsive navigation bar using breakpoints?
28How would you handle images that need to resize at specific breakpoints? How can you make font sizes scale smoothly between two breakpoints?
29How would you debug a layout that looks broken at a specific breakpoint?
30How would you optimize breakpoints for tablets vs. phones?
31How can you prevent layout jumps between breakpoints?
32How do you use CSS custom properties (variables) with breakpoints?
33How do breakpoints differ between desktop, tablet, and mobile-first strategies?
22 / 33

How can you use logical operators (and, not, only) in media queries?

Using Logical Operators in CSS Media Queries

CSS media queries support logical operators such as and, not, and only to combine or restrict conditions for applying styles. These operators allow developers to create precise and complex responsive design rules that target specific scenarios.

Types of Logical Operators in Media Queries
  1. 1

    and — Combines multiple conditions so that all must be true for the styles to apply.

  2. 2

    not — Excludes styles from applying when a certain condition is true.

  3. 3

    only — Prevents older browsers that do not support media queries from applying the contained styles.

Example: Using and, not, and only Operators

In this example, and ensures styles apply only when both conditions match, not excludes certain viewports, and only safeguards modern media query syntax from older browsers. These logical operators make media queries more powerful and flexible in responsive design.

Difficulty: 3/10
Topics: logical operators in media queries, responsive breakpoint logic, CSS selector combinators

Scenario Questions

0-2 years experience
  1. 1

    You're building a mobile-first layout and need to apply a different font size only when the screen is wider than 768px and not in landscape mode. How would you write that media query?

  2. 2

    A teammate wrote a media query using 'not screen and (max-width: 600px)' but the styles aren't applying as expected. What’s likely wrong, and how would you fix it?

  3. 3

    If you use 'only screen and (min-resolution: 2dppx)', what browsers are you trying to target, and why is 'only' important here?

2-5 years experience
  1. 1

    Our responsive navigation breaks on iPads in portrait mode — the media query uses 'not screen and (max-width: 1024px)' but still triggers on tablets. Why is this happening, and how would you debug and fix it?

  2. 2

    We have a component that should show a high-res image only on retina displays and when the user prefers reduced motion. How would you combine these conditions with logical operators, and what edge cases might you miss?

  3. 3

    A CSS file with nested media queries using 'and' and 'not' is causing inconsistent styling across browsers. How would you refactor it to improve maintainability and avoid unintended overrides?

5-8 years experience
  1. 1

    We're migrating a legacy site that uses 'only screen' to support old iOS devices, but now we want to drop support for browsers that don't understand media queries v4. How would you redesign the media query strategy to balance backward compatibility and modern features without bloating CSS?

  2. 2

    Our design system uses complex media queries with multiple logical operators to handle breakpoints, print, dark mode, and reduced motion. How would you structure and document these to prevent team-wide bugs during feature development?

  3. 3

    A performance audit shows that our media queries with 'not' and multiple 'and' conditions are causing layout thrashing on low-end devices. How would you optimize the CSS architecture to reduce reflows without losing functionality?

8+ years experience
  1. 1

    We're standardizing responsive design across 12 product teams, but some use 'only' for legacy support while others avoid it entirely. How would you design a company-wide CSS media query policy that balances maintainability, performance, and cross-browser support over a 5-year horizon?

  2. 2

    Our CSS-in-JS library auto-generates media queries with logical operators based on design tokens, but it's producing invalid queries when combining 'not' with multiple features. How would you architect a validation and linting layer to prevent this at build time across thousands of components?

  3. 3

    A legacy product still relies on 'only screen' to hide styles from IE8, but we're now using CSS custom properties that IE doesn't support. How would you phase out the old media query patterns without breaking existing users or forcing a full rewrite?

Follow-up Questions

  • What happens if you use 'not' without specifying a media type?
  • Why would you choose 'only' over just using 'and'?
  • How would you test if your media query with logical operators is working correctly on an old iOS device?