दिन 10: Accessibility (a11y) की ज़रूरी बातें
✅ आज आप सीखेंगे
- Accessibility किसे चाहिए (सोच से ज़्यादा लोग)
- नींव के रूप में semantic HTML
- Keyboard access, focus और skip links
- ARIA: कब इस्तेमाल करें – और कब नहीं
- 10-point accessibility audit
🏢 असली दुनिया में
कमज़ोर नज़र वाले retired teacher Mr. Kapoor मिठाई order करने के लिए phone का screen reader इस्तेमाल करते हैं। हाथ की चोट के बाद उनकी पोती सिर्फ़ keyboard चलाती है। अगर Sharma Sweets की website इनके लिए काम न करे, तो दुकान वफ़ादार customers खोती है – और कई देशों में inaccessible sites पर क़ानूनी कार्रवाई भी होती है।
किसे फ़ायदा?
नियम 1: सही element लें
Inaccessible
- <div onclick="order()">Order</div>
- Tab से focus नहीं
- Screen reader सिर्फ़ “Order” कहता है
- Enter key कुछ नहीं करती
Accessible
- <button type="button">Order</button>
- अपने-आप focus होता है
- “Order, button” बोला जाता है
- Enter और Space चलते हैं
<div onclick="alert('div clicked')" style="display:inline-block;padding:6px 12px;background:#e34f26;color:#fff;border-radius:6px">Fake button (div)</div>
<button type="button" onclick="alert('button clicked')">Real button</button>
<p>Press <kbd>Tab</kbd> inside this box: only the real button gets focus.</p>नियम 2: सब कुछ keyboard से चले
<style>
.skip{position:absolute;left:-999px} .skip:focus{left:8px;top:8px;background:#fff;padding:6px;border:2px solid #e34f26}
a:focus-visible,button:focus-visible,input:focus-visible{outline:3px solid #f59e0b;outline-offset:2px}
</style>
<a class="skip" href="#main">Skip to main content</a>
<nav><a href="#">Home</a> · <a href="#">Menu</a> · <a href="#">Contact</a></nav>
<main id="main" tabindex="-1"><h1>Sharma Sweets</h1>
<label>Search <input type="search"></label> <button>Go</button>
</main>| करें | बचें |
|---|---|
| Natural tab order (source order) रखें | tabindex="1", "2"… positive values |
| साफ़ focus outline दिखाएँ | बिना विकल्प के outline: none |
| पहले item के रूप में skip link | Keyboard traps (जिन modals से निकल न सकें) |
| tabindex="-1" सिर्फ़ script से focus के लिए | div/span पर सिर्फ़-click actions |
नियम 3: text विकल्प और साफ़ भाषा
- Images पर अर्थपूर्ण
alt; सजावट के लिएalt=""(Day 4)। - हर form field का दिखने वाला <label> (Day 6)।
- Link text बताए कहाँ जाएगा – “click here” कभी नहीं (Day 3)।
- Video के captions (<track kind="captions">), audio का transcript।
- html पर
lang="en"और Hindi text परlang="hi"ताकि screen readers सही आवाज़ लें।
<p lang="hi">ताज़ी मिठाइयाँ, रोज़ सुबह।</p> <video controls width="320" src="/assets/img/tutorials/html/shop.mp4"> <track kind="captions" srclang="en" label="English" src="captions-en.vtt"> </video>
नियम 4: रंग और contrast
<p style="color:#bbb">Light grey text on white – hard to read (contrast 1.9:1) ❌</p> <p style="color:#555">Dark grey on white – easy to read (contrast 7.5:1) ✅</p> <p><span style="color:red">Red = sold out</span> ❌ colour only</p> <p><span style="color:#b91c1c">✖ Sold out</span> ✅ icon + text + colour</p>
WCAG सामान्य text के लिए कम से कम 4.5 : 1 और बड़े text के लिए 3 : 1 माँगता है। Chrome DevTools colour inspect करने पर contrast ratio दिखाता है।
ARIA – आख़िरी उपाय
<button type="button" aria-label="Close offer banner">✕</button>
<button type="button" aria-expanded="false" aria-controls="m1"
onclick="const o=this.getAttribute('aria-expanded')==='true';this.setAttribute('aria-expanded',!o);document.getElementById('m1').hidden=o;">☰ Menu</button>
<ul id="m1" hidden><li>Home</li><li>Menu</li></ul>
<p>Cart: <span aria-live="polite" id="c">0 items</span>
<button type="button" onclick="c.textContent=(parseInt(c.textContent)+1)+' items'">Add ladoo</button></p>| ARIA | उद्देश्य |
|---|---|
| aria-label | सिर्फ़-icon control का नाम (✕, ☰, 🔍) |
| aria-labelledby / aria-describedby | Element का नाम/विवरण बताने वाले दिखते text की ओर इशारा |
| aria-expanded | Menu/accordion खुला है या नहीं |
| aria-live="polite" | बदलते content की घोषणा (cart count, form status) |
| aria-hidden="true" | सजावटी icons screen readers से छिपाएँ |
| role="alert" | Errors जैसे ज़रूरी संदेश |
अगर कोई native HTML element पहले से काम करता है (button, nav, label, details), तो ARIA की जगह वही लें। ग़लत ARIA, बिना ARIA से बुरा है।
10-point quick audit
- Mouse हटा दें – क्या Tab, Enter, Space, Esc से पूरा page चलता है?
- क्या focus outline हमेशा दिखती है?
- क्या हर image का सही alt है?
- क्या हर field का label है?
- क्या ठीक एक h1 और तार्किक heading क्रम है?
- क्या link और button text बिना संदर्भ के भी साफ़ हैं?
- Contrast ≥ 4.5:1?
- 200% zoom – क्या content अब भी fit होता है?
- html lang set; Hindi हिस्से lang="hi"?
- Lighthouse चलाएँ (Chrome DevTools → Lighthouse → Accessibility) और list ठीक करें।
🏅 आज के Job Skills
Practice tasks
🏋️ Practice – ख़ुद करें
<div onclick="buy()">🛒</div> <img src="ladoo.jpg"> <input placeholder="Mobile">Solution देखें
<button type="button" onclick="alert('added')" aria-label="Add to cart">🛒</button>
<img src="/assets/img/tutorials/html/ladoo-400.webp" alt="Besan ladoo, ₹500 per kg" width="160" height="120">
<label for="mob">Mobile</label> <input id="mob" type="tel" autocomplete="tel">Quick quiz
🧠 Quick Quiz – ख़ुद को जाँचें
Interview corner
💼 Interview Corner
ARIA का पहला नियम क्या है?
अगर native HTML element या attribute ज़रूरी semantics और व्यवहार देता है, तो ARIA न लें। Native elements में keyboard support और सही roles मुफ़्त मिलते हैं।
Accessibility कैसे test करते हैं?
जल्दी के सुधारों के लिए automated tools (Lighthouse, axe), फिर manual जाँच: सिर्फ़-keyboard navigation, screen reader (NVDA/TalkBack/VoiceOver), 200% zoom, contrast जाँच, और बेहतर हो तो disabled users के साथ testing।
सारांश
- Native semantic elements मुफ़्त में accessibility देते हैं।
- सब कुछ keyboard से चले, दिखते focus और skip link के साथ।
- Text विकल्प, labels, captions, lang और contrast ≥ 4.5:1।
- ARIA सिर्फ़ कमी भरता है; keyboard, screen reader और Lighthouse से audit।
Day 11: interactive HTML – details/summary, dialog, progress, meter, template और data attributes।
