Questions
29 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?
29 / 49

How can you visually hide an element but keep it accessible for screen readers?

Hiding Elements Visually While Keeping Them Accessible in CSS

In CSS, you can hide elements from sighted users while still allowing screen readers to access their content. This technique is essential for accessibility, ensuring important instructions or labels remain available to assistive technologies.

Common Methods and Their Effects
  1. 1

    display: none – Completely removes the element from the layout and accessibility tree. Screen readers cannot access it.

  2. 2

    visibility: hidden – Hides the element visually but still takes up space in the layout. However, most screen readers will ignore it.

  3. 3

    Visually hidden (off-screen technique) – Keeps the element in the accessibility tree but makes it invisible on screen using positioning and clipping.

Example: Visually Hidden but Accessible Text

In this example, the text 'Close menu' is hidden visually but remains readable by screen readers. The clip and position properties ensure the text is moved off-screen while still accessible to assistive technologies.

Best Practices
  1. 1

    Use the .visually-hidden class to hide text intended only for screen readers.

  2. 2

    Avoid using display: none or visibility: hidden for content that needs to be read by assistive technologies.

  3. 3

    Test with screen readers (like NVDA or VoiceOver) to confirm accessibility behavior.

  4. 4

    Apply visual hiding only when necessary, such as for hidden labels or additional context.

Difficulty: 5/10
Topics: visually hidden, screen reader accessibility, CSS techniques

Scenario Questions

0-2 years experience
  1. 1

    You need to hide a decorative icon in a navigation bar but still have it read by screen readers. Which CSS rule would you apply and why?

  2. 2

    If you set display:none on an element, what happens to screen reader accessibility? How would you change that to keep it accessible while invisible?

2-5 years experience
  1. 1

    We have a modal component where the background overlay should be invisible but still announced for focus management. Explain how you'd hide it visually while preserving screen reader access, and discuss any trade‑offs with other CSS properties.

  2. 2

    During QA you notice a visually hidden label is not being read by VoiceOver. Walk me through your debugging steps and how you’d adjust the CSS.

5-8 years experience
  1. 1

    Our design system includes a utility class for visually hidden text used across many components. Describe how you'd implement it to be robust across browsers, support high‑contrast mode, and avoid layout shifts. What edge cases would you consider?

  2. 2

    When refactoring a large legacy codebase, you find multiple patterns for hiding elements (e.g., opacity:0, visibility:hidden). How would you consolidate them into a single accessible approach and ensure no regressions?

8+ years experience
  1. 1

    We plan to migrate our UI library to a new theming system and want to guarantee that all visually hidden elements remain accessible. How would you architect the CSS/utility framework, tooling, and testing strategy to enforce this at scale across multiple teams?

  2. 2

    Discuss the long‑term maintenance implications of using a custom visually-hidden mixin versus native HTML attributes like aria-hidden. When might you choose one over the other in a large product ecosystem?

Follow-up Questions

  • Can you think of any cases where you would deliberately exclude a visually hidden element from the accessibility tree?
  • How does this technique interact with focus management and keyboard navigation?
  • What impact does high‑contrast mode or zoom have on a visually hidden element?