Questions
40 of 49
1What is the display property in CSS used for?
2What is the default display value for <div>, <span>, <p>, and <a> tags?
3What is the difference between display: block and display: inline?
4How does display: inline-block behave?
5What happens when you set display: none on an element?
6How is display: none different from visibility: hidden?
7Can display: none affect layout reflow or accessibility?
8What’s the effect of display: block on inline elements like <span>?
9What’s the difference between display: table and actual HTML <table> elements?
10How do replaced elements (like <img> or <input>) behave with different display values?
11How is display: flex different from display: block?
12What is the difference between display: grid and display: flex?
13What happens if you apply display: inline-flex to a container?
14What is the difference between display: contents and display: none?
15What is display: list-item, and when is it used?
16How does display: run-in work, and why is it rarely used?
17What’s the difference between display: inline-grid and display: grid?
18How can you make an element behave like both inline and block elements?
19What happens to child elements when the parent has display: contents?
20How does the display property affect box model calculations?
21How can you change a block-level element to behave like an inline element without changing its tag?
22How do you center elements using display: flex or display: grid?
23How can you hide elements but keep their layout space?
24What happens to child elements when their parent has display: none?
25How can display: contents help improve semantic markup but hurt accessibility?
26What happens if you set display: flex on the <body> tag?
27How do you use display to build responsive layouts?
28What is the difference between using display and position to arrange elements?
29How can you visually hide an element but keep it accessible for screen readers?
30How does display affect stacking and z-index behavior?
31Does display: none remove an element from the DOM?
32Can an element with display: none trigger CSS transitions or animations?
33How does display interact with CSS pseudo-elements (::before, ::after)?
34What is the difference between visibility: collapse and display: none in table elements?
35How can you make text and icons align properly using display values?
36How do block formatting contexts relate to display types?
37What happens if you apply display: table to a flex container?
38How does display behave differently for replaced vs. non-replaced elements?
39Can display be animated using CSS transitions?
40How does display affect the accessibility tree and ARIA roles?
41How can you make a <li> element appear horizontally instead of vertically?
42How do you create a two-column layout without using float or position, using only display?
43How do you make an image and text sit side by side neatly?
44How would you make a navigation menu horizontally aligned using display?
45How can you make all elements behave as border-box and block-level by default?
46How would you use display: flex to make a footer stick to the bottom?
47How can display: grid simplify responsive design compared to floats?
48When would you prefer display: inline-flex over display: flex?
49How can you use display: contents to remove extra wrappers in semantic HTML structures? How can incorrect use of display lead to accessibility or SEO problems?
40 / 49

How does display affect the accessibility tree and ARIA roles?

Difficulty: 6/10
display property, accessibility tree, ARIA roles

Impact of CSS Display on Accessibility and ARIA Roles

The CSS display property affects whether elements are included in the accessibility tree and how assistive technologies interpret them. Certain display values can make content invisible to screen readers or alter how ARIA roles are perceived.

Key Points
  1. 1

    display: none – Removes the element from both visual layout and the accessibility tree. Screen readers will not announce it, and ARIA roles applied to it have no effect.

  2. 2

    visibility: hidden – Hides the element visually, and most screen readers ignore it, though it still occupies layout space.

  3. 3

    Other display values (block, inline, flex, grid, etc.) keep the element in both the visual layout and accessibility tree, allowing ARIA roles to function correctly.

  4. 4

    Use visually hidden techniques (off-screen positioning with clip and position) if you want an element hidden visually but still accessible to assistive technologies.

Example: Visually Hidden Accessible Content

Here, the 'Close menu' text is hidden visually but still accessible to screen readers. Using display: none instead would remove it from the accessibility tree and prevent assistive technologies from reading it.

Best Practices
  1. 1

    Avoid display: none for content that should remain accessible to screen readers.

  2. 2

    Use visually hidden techniques for labels, instructions, or ARIA descriptions that should be read but not displayed.

  3. 3

    Test accessibility using tools like NVDA, VoiceOver, or Lighthouse to confirm ARIA roles are effective.

  4. 4

    Combine proper semantic HTML and ARIA roles with careful use of display and visibility properties to ensure full accessibility.

Scenario Questions

0-2 years experience

  1. 1If you set an element's CSS to `display:none`, what happens to its presence in the accessibility tree, and how does that affect screen reader users?
  2. 2You have a button that visually looks like a link using `display:inline-block`. Does changing its display affect its ARIA role, and what should you verify?
  3. 3When you change a container from `display:flex` to `display:block`, how might that impact the way assistive technologies interpret its child elements?

2-5 years experience

  1. 1We noticed that a modal dialog stopped being announced by screen readers after we switched its wrapper from `display:none` to `visibility:hidden` before showing it. Why did that happen, and how would you fix it?
  2. 2During a feature rollout, a list of items rendered with `display:grid` is missing from the accessibility tree in Chrome but appears in Firefox. What could be causing the discrepancy, and how would you debug it?
  3. 3You need to hide decorative icons visually but keep them accessible. Which CSS display values would you use, and why?

5-8 years experience

  1. 1Design a reusable component library where certain components can be toggled hidden via CSS. How would you ensure that using `display:none` versus other techniques doesn't unintentionally break ARIA relationships across the app?
  2. 2Our large‑scale dashboard uses `display:contents` to flatten DOM for layout, but some assistive tech reports missing landmarks. Explain the trade‑offs and propose a strategy to maintain accessibility while keeping the layout benefits.
  3. 3When implementing virtual scrolling, rows are added/removed with `display:none` to keep DOM size low. Discuss the impact on the accessibility tree and how you'd mitigate performance and usability concerns.

8+ years experience

  1. 1We are migrating a legacy codebase that heavily uses `display:none` to conditionally hide sections. How would you architect a migration plan that preserves ARIA semantics and minimizes regression risk across multiple teams?
  2. 2At the organization level, we need a policy for CSS techniques that affect the accessibility tree. What guidelines would you set for using `display:none`, `visibility:hidden`, `opacity:0`, and off‑screen positioning, and how would you enforce them in CI?
  3. 3Consider a cross‑platform web app that must support both native screen readers and emerging voice‑controlled browsers. How would you design a CSS strategy that balances visual layout (including flex, grid, and `display:contents`) with consistent accessibility tree behavior across these environments?

Follow-up Questions

  • Can you give an example where `display:contents` caused an ARIA role to be lost?
  • What alternative CSS approaches would you use to hide content while preserving its role?
  • How do you verify that your hiding technique works across different screen readers?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.