Performance: Global attributes
Global attributes affect how elements behave and interact, impacting rendering and user experience consistency.
<button aria-label="Button">Click me</button>
<div onclick="doSomething()" tabindex="0" aria-label="Button">Click me</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using many global attributes on non-semantic elements | Increased event listeners | Multiple reflows on interaction | Moderate paint cost | [X] Bad |
| Using semantic elements with minimal global attributes | Minimal event listeners | Single reflow on interaction | Low paint cost | [OK] Good |
id attribute assigns a unique identifier to an element, usable on all elements.id -> Option Cid [OK]id for unique element IDs on any tag [OK]src as global (it's for images, scripts)href works on all elements (only links)alt outside imagestitle attribute is a global attribute that shows a tooltip on hover.title="Info" is the correct syntax to add tooltip text.title="Info" -> Option Btitle [OK]title for tooltips on any element [OK]tooltip attributealt (only for images)<div hidden>Secret message</div><div>Visible message</div>
hidden attribute effecthidden global attribute hides the element from display in the browser.hidden, so 'Secret message' is hidden. The second <div> is visible.hidden hides element = Only visible message shown [OK]hidden hides element from view instantly [OK]hidden just makes element transparenthidden with CSS display:none<button id="btn1" class="btn" hidden="false">Click me</button>
hidden attribute usagehidden attribute is a boolean attribute and should not have a value like "false"; presence means true.id and class are valid global attributes on button. The error is only with hidden="false".hidden attribute should not have a value -> Option Dhidden no value [OK]hidden="false" means visibleclass and hidden conflictdata- allow storing extra info without affecting display or behavior.data-product-info is a valid custom data attribute to hold product details invisibly.data-product-info -> Option Adata-* attributes [OK]data-* attributes to store hidden info [OK]title which shows visible tooltiphidden which hides elementclass which is for styling, not dataPass the test and this pattern moves unknown