RSS FeedTwitterMastodonBlueskyShare IconHeart IconGithub IconArrow IconClock IconGUI Challenges IconHome IconNote IconBlog IconCSS IconJS IconHTML IconShows IconOpen Source Software IconSpeaking IconTools IconShuffle IconNext IconPrevious IconCalendar IconCalendar Edit IconNotebook IconObservable Notebooks IconSlash IconGoogle G Icon
a named container query example
A cartoon skull with a hotpink hat on.3 min read

Web elements know about the user, device, variables, layout and more

css

Since I've tried and failed like 3 times to try and write a blog post on "sector driven design" or "smart components," this post is just gonna try and elaborate on what Miriam Suzanne kids a li'l and says "containers know stuff."

This is huge though, for development and design.

Components/elements/containers whatever, can own all their presentation aspects for nearly any scenario now. They can feel like magic, perfectly adapting to wherever the component author or designer has condoned.

A new one that not enough people talk about is, CSS named container queries. A component can easily know if it's in the sidenav, footer, article area, callout, whatever!

@container --some-area {

}

That's amazing.

No more chasing down all the styles and variations that scatter across your application.

Components are aware of it's user, device, variables, layout and more. In an attempt to get y'all stoked too, here's a list of all the "stuff" that components know.

What kind of stuff? #

Let's create the ultimate list of all the rad "stuff" that components know:

  1. the users preferences
    (dark/light, reduced motion, forced-colors, etc)
  2. the users writing and reading preferences
    (rtl, lrt, etc)
  3. the user's device size, orientation, and capabilities
    (color, pointer, etc)
  4. the app's design system
    (colors, spacing, etc)
  5. where they are in the app
    (container name queries)
  6. how much space they have
    (container size queries)
  7. how many items they contain
    (quantity query)
  8. what kind of items they contain
    (:has())
  9. what the value of a variable for them is
    (style query)
  10. whats in or out of view
    (scroll animations)
  11. whether its scrolling or not
    (scroll-state)
  12. is the user hovering, focusing or activating elements
  13. whether there's focus within or not
    (focus-within)
  14. if there's valid in invalid form inputs
    (validity)
  15. position within siblings
    (sibling-count() or sibling-index())
  16. Moved to or is in an iframe
    (if (window.self !== window.top))
  17. is defined or not
    (:defined)
  18. if media is playing or not
    (:playing)
  19. is being printed and/or fragmented across print pages
    (@media print)

Let me know in the comments what I missed.
I'll give ya a shout for your recommendation 🤘🏻💀

Shouts #

  • Nathan Knowler - Position amongst siblings, media pseudo classes like :playing and web components being :defined or not
  • Anthony Frehner - Moved to or is in an iframe
  • Michael G - Being printed and/or fragmented across print pages

10 comments #

37likes
17reposts
  • Web Directions
  • Anthony Frehner
  • Felix
  • Martin Splitt
  • William Oliveira
  • Tab Atkins-Bittner
  • Alexander Lehner
  • Wim Leers
  • Jack Iakovenko
  • Cyd Stumpel
  • Charis
  • JW
  • William Killerud
  • Daniel
  • Carol McKay (she / her)

Join the conversation on

@argyleink Some browser specific ones:

- In Chrome, position amongst siblings: `sibling-index()` and `sibling-count()`.
- In Safari, a whole bunch info about media (i.e. playing, paused, buffering, stalled).

Both of those are fantastic for sequencing animations.

Nathan KnowlerNathan Knowler

@argyleink Oh a good one: whether or not they as a custom element are defined (`:defined`).

Nathan KnowlerNathan Knowler
If they’ve moved to an iframe!
Anthony FrehnerAnthony Frehner
p.s. i dont specifically mean web components i just mean any web element, component, thing… aka; CSS can know
Adam ArgyleAdam Argyle
wait... you can use CSS vars in container queries now?
GordonGordon
whether they are on a printed page, on what kind of page (left, right etc.) and of they have enough space to fit on the page (css fragmentation).
Michael GMichael G
not exactly… but you can calc()! nerdy.dev/carousel-ada...?
Adam ArgyleAdam Argyle

@argyleink I might be missing the point here, but I feel like all of the lifecycle callbacks are missing. Whether an element is in the DOM, when it's taken out, when it's moved, when its attributes change. Not to mention all the form-associated callbacks; they can detect being moved to other forms, when a form they're in is being reset, and even when a form state is being restored by the browser.

vrugtehagelvrugtehagel
throw in a browserhack or two and it knows which browser it's in ????‍♂️????
Bart VenemanBart Veneman