hn.today

Useful Custom-Media Presets

blog.master.dev4 points0 comments
Screenshot of Useful Custom-Media Presets

CSS `@custom-media` lets developers give reusable names to media-query conditions, making repeated responsive rules easier to read and maintain. The feature is still experimental: Firefox 148 supports it behind a flag, while Chrome and Safari do not yet offer general support. Container style queries provide an alternative syntax available across browsers, though they have limitations, including inability to style the root element directly and restrictions on combining container and media conditions. A PostCSS plugin is another option for preparing code for broader support.

The suggested presets focus on device capabilities rather than treating screen width as a proxy for “mobile,” “tablet,” or “desktop.” They classify primary input as mouse, touch, stylus, air pointer, or directional-pad control using hover and pointer features. Since browsers cannot reliably identify which of several connected inputs a person is using, the guidance is to target the primary input and use `any-hover` or `any-pointer` as additions for specific combinations. For responsive layouts, it proposes minimum-width breakpoints every 100 pixels from 360 to 1560 pixels, with optional upper bounds or combined ranges. Finally, it defines “true HDR” as requiring both high dynamic range and a P3 color gamut, helping avoid HDR media that looks washed out or unusually dark on unsuitable displays.

Read on blog.master.dev0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Web

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.