Elektrine lite

← Feed

@css@front-end.social

2026-09-26 21:26 UTC

a11y question: Let's suppose I have an empty html element somewhere on the page with 0 content, invisible*, having position:absolute (or fixed). It has no purpose in the HTML (only used for some CSS stuff). Is it a good idea to add the "inert" attribute? Or should I do nothing? * It may or may not have a size, but no style to make it visible. #A11y #HTML

Replies (3)

  • @cwilcox808@c.im 2026-09-26 21:36

    @css@front-end.social So a div or span? If it has no content (including no descendant pseudo-elements with content), it's already not in the accessibility tree so `inert` does nothing.

    Open ##5221546

  • @jcsteh@aus.social 2026-09-26 22:11

    @css@front-end.social I'd lean toward role=none. It's a little bit safer in the sense that if you one day forgot and stuck content inside that container, only the container would be pruned from the accessibility tree, not the content. In contrast, with inert, the entire subtree gets removed from the accessibility tree, and if it's not interactive, you'd never know because the inert attribute doesn't have any default visual styling. Imo, this makes the inert attribute dangerous and best avoided unless it's absolutely necessary.

    Open ##5221558

  • @VerdettoQR@mastodon.social 2026-09-27 00:20

    @css@front-end.social A ::before or ::after on the nearest real element does the same CSS job with no node, so nothing needs inert or role=none. If it must stay a real element, jcsteh's role=none keeps any content added later reachable. Is it there for a hook a pseudo-element cannot give, like a sibling selector?

    Open ##5221559