← Back to HTML Course | Chapter 10: Reference & Interview Prep | Lesson 7 of 20

HTML ARIA रोल्स

ARIA का मतलब है Accessible Rich Internet Applications। ARIA roles और attributes invisible labels की तरह हैं जिन्हें आप HTML elements में जोड़ते हैं ताकि screen readers को समझ आए कि आपके page का हर हिस्सा क्या करता है। इसे उन users के लिए subtitles जोड़ने जैसा समझें जो आपका page देख नहीं सकते।
Syntax
markup
<tagname role="rolename" aria-label="label">content</tagname>

ARIA रोल्स क्या हैं

एक ARIA role assistive technology को बताता है कि कोई element क्या करता है। उदाहरण के लिए role=navigation किसी screen reader को बताता है कि यह एक navigation area है, भले ही वह सिर्फ एक div हो।

जिन elements में पहले से सही native semantics हैं (जैसे किसी actual button tag पर role=button इस्तेमाल करना) उन पर roles का overuse करना अनावश्यक है और confusion भी पैदा कर सकता है।

Note:
  • पहले semantic HTML इस्तेमाल करें।
  • जब semantic HTML आपकी ज़रूरत का meaning express नहीं कर सकता, तभी ARIA roles जोड़ें।
Warning: गलत ARIA roles जोड़ना, कोई भी न जोड़ने से भी बुरा है — यह screen reader users को actively गुमराह करता है।

उदाहरण: What are ARIA Roles

markup
<div role="navigation">Site links here</div>

aria-label और aria-describedby

aria-label उन elements के लिए एक text description देता है जिनका कोई visible label नहीं है। aria-describedby किसी element को page पर कहीं और मौजूद एक लंबी description से जोड़ता है।

दोनों को साथ इस्तेमाल करना आम है: accessible name के लिए एक छोटा aria-label और अतिरिक्त supporting detail के लिए aria-describedby।

Note: icon-only buttons पर aria-label इस्तेमाल करें ताकि screen readers उनका purpose बता सकें।
Warning: जिन elements में पहले से visible text है, उन पर aria-label इस्तेमाल न करें — यह screen readers के लिए visible label को override कर देता है।

उदाहरण: aria-label and aria-describedby

markup
<button aria-label="Close" aria-describedby="closeHint">X</button>
<span id="closeHint">Closes this dialog</span>

Toggles के लिए aria-expanded

aria-expanded assistive technology को बताता है कि dropdown menu या accordion panel जैसा कोई collapsible element फिलहाल open है या closed, और element की state बदलते ही इसकी value को JavaScript से dynamically update किया जाना चाहिए।

उदाहरण: aria-expanded for Toggles

markup
<button aria-expanded="false" onclick="this.setAttribute('aria-expanded', 'true')">
  Show menu
</button>

Dynamic Content के लिए aria-live

aria-live page के उस region को मार्क करता है जो बिना full page reload के dynamically update होता है, और screen readers को बताता है कि नए content को अपने आप announce करें, बजाय इसके कि user मैन्युअल तरीके से वहाँ वापस navigate करे।

उदाहरण: aria-live for Dynamic Content

markup
<div aria-live="polite" id="status">Loading...</div>

लैंडमार्क रोल्स

banner, main, complementary, और contentinfo जैसे landmark roles page के प्रमुख regions को मार्क करते हैं, जिससे screen reader users हर element को एक-एक करके tab करने के बजाय सीधे sections के बीच जंप कर सकते हैं।

उदाहरण: Landmark Roles

markup
<div role="banner">Header</div>
<div role="main">Main content</div>
<div role="contentinfo">Footer</div>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.