Introduction
Global attributes let you add extra information or control to any HTML element. They help make your webpage easier to use and understand.
Global attributes let you add extra information or control to any HTML element. They help make your webpage easier to use and understand.
<element global-attribute="value">Content</element>
id, class, style, title, and hidden.<div id="header">Welcome</div>
<button title="Click me">Press</button>
<p hidden>This text is hidden and not shown on the page.</p>
<span data-info="123">Info</span>
This example shows several global attributes in action:
id and class on the heading for styling.title to show a tooltip on the heading.hidden to hide a paragraph.data-action and aria-label on the button for custom data and accessibility.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Global Attributes Example</title> <style> #main { color: darkblue; font-weight: bold; } .highlight { background-color: lightyellow; } </style> </head> <body> <h1 id="main" class="highlight" title="Main heading">Hello World</h1> <p>This paragraph is visible.</p> <p hidden>This paragraph is hidden and will not show.</p> <button data-action="save" aria-label="Save button">Save</button> </body> </html>
Use id to uniquely identify elements for CSS or JavaScript.
The hidden attribute hides the element from the page and screen readers.
Custom data attributes start with data- and are useful for storing extra info.
Global attributes work on all HTML elements.
They help with styling, accessibility, behavior, and adding extra info.
Common ones include id, class, title, hidden, and data-*.
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