Web design and digital-business ideas grounded in real tasks.

Use display: contents Only After Checking the Accessible Structure

A developer reviewing a web page and its code on two screens.
AI-generated photographic illustration; not documentary photography.

A wrapper gets in the way of a grid layout, so a developer adds display: contents. The children now participate in the surrounding layout without the wrapper’s usual box. The screen can look exactly right while another part of the interface needs a closer check.

MDN’s display documentation warns that some browser implementations can remove an element with this value from the accessibility tree. Behaviour depends on the element and implementation, so a visually successful change is not a complete accessibility test.

Know what the wrapper contributes

Before changing it, identify whether the element carries meaning: a list, group, landmark, label relationship or interactive role. A generic layout wrapper and a semantic element do not necessarily have the same consequences when their representation changes.

Write down the reason for using the property. If the only aim is to place items into a grid, compare whether a different markup or layout arrangement achieves the goal with fewer assumptions.

Test the structure a user encounters

Inspect the accessibility tree in the browsers your project supports. Then test the relevant reading and navigation behaviour with appropriate assistive technology. Check whether the expected role, name, grouping and relationships remain available.

For a hypothetical list of options, the visual order may be unchanged while the announced structure differs. The test should therefore ask whether a user receives the list context, not only whether every text item is still visible.

Keep a small regression example

Save a minimal page that reproduces the element and layout you depend on, along with the browser and assistive-technology versions checked. A later update can change implementation behaviour, and a focused example makes retesting easier.

Do not replace a real semantic problem with an untested collection of ARIA attributes. First understand what disappeared and whether avoiding the property is the clearer solution.

display: contents can be useful, but its benefit should survive both kinds of inspection: how boxes are arranged and how the interface is understood. The layout is finished only when the required structure works for the people who use it.