Performance: Screen reader utilities
This affects how accessible content is presented to screen readers without impacting visual rendering or page load speed.
<div class="visually-hidden">Hidden text</div>
<div style="display:none">Hidden text</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| display:none to hide content | Normal DOM nodes | 0 reflows | No paint for hidden content | [X] Bad (loses accessibility) |
| Bootstrap visually-hidden class | Normal DOM nodes | 0 reflows | No paint for hidden content | [OK] Good (accessible and performant) |
.visually-hidden class?.visually-hidden.visually-hidden to hide content visually but keep it accessible..hidden hides content completely including from screen readers; .sr-only was used in older versions; hidden attribute hides from all users including screen readers.<button>Submit<span class="visually-hidden"> form</span></button>
.visually-hidden.visually-hidden text is invisible but still read by screen readers.<span class="sr-only">Hidden info</span>
.sr-only with .visually-hidden..sr-only may not apply correct styles, so text might not be hidden visually.sr-only is deprecated in Bootstrap 5 -> Option B<span class="visually-hidden"> with the extra text inside the button uses .visually-hidden, which hides visually but keeps text accessible. Add a <div hidden> with the text inside the button uses hidden attribute which hides from screen readers. Add a <span style="display:none"> with the text inside the button uses CSS display:none which also hides from screen readers. Add a <span> with the text and set font-size to 0 hides text visually but may cause layout issues or be unreliable.Pass the test and this pattern moves unknown