DEV Community

Robert Rees
Robert Rees

Posted on

Media Queries Level 4

Media Queries Level 4 may sound like possibly the worst D&D character class but offer a huge simplification on how to specify page-size responsive CSS.

It introduces the ability to write media queries using the "<=>" operators.

The previous way of writing conditions was based on min-width and max-width. And the thing I found confusing about it is that the max option meant "up to this width" and the min option meant "from this width".

This may not be too hard to understand when you have one size that triggers a change but typically you have a few ranges where different layouts and configurations of viewable elements apply. Writing these as a set of max widths and making it maintainable amongst multiple people felt like an art.

With the new standard though you can now write selectors in the following form: @media (400px <= width <= 700px) { … }. I think this is very easy to understand and is closer to what you would intuitively expect to be writing. It also closes the gap between pixel pushing designs and the code you're writing to implement it.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay