स्क्रीन रीडर इस्तेमाल करने वाले पेज को उसकी हेडिंग से टटोलते हैं, जैसे देखने वाले पाठक मोटी पंक्तियों पर नज़र दौड़ाते हैं।हेडिंग का स्तर बताता है कि उसका सेक्शन रूपरेखा में कहाँ है, यह नहीं कि टेक्स्ट कितना बड़ा है: आकार सीएसएस तय करता है।
इसे माउस, कीबोर्ड या स्क्रीन रीडर से इस्तेमाल करें।साथ का इंस्पेक्टर दिखाता है कि आपके इस्तेमाल के दौरान ब्राउज़र सहायक तकनीक को क्या बताता है: फ़ोकस, स्थिति में बदलाव और घोषणाएँ।
हेडिंग
0मिले
H1इस पेज का अपना नाम, डेमो के ऊपर
हेडिंग जैसा दिखता है, पर है नहीं
हर स्तर अपने से पहले वाले के ठीक बाद आता है।
उदयपुर में एक वीकेंड
लेखक: मीरा अय्यर · 6 मिनट में पढ़ें
झीलें, महल और छत पर डिनर: पुराने शहर के लिए दो दिन काफ़ी हैं, अगर आप सुबहें सोच-समझकर बिताएँ।
कैसे पहुँचें
ट्रेन से
दिल्ली से रात भर चलने वाली ट्रेनें सुबह-सुबह उदयपुर सिटी स्टेशन पहुँचती हैं।
हवाई जहाज़ से
हवाई अड्डा पुराने शहर से क़रीब 22 किमी दूर है, टैक्सी से 40 मिनट का रास्ता।
कहाँ ठहरें
हवेली गेस्टहाउस गणगौर घाट के पास हैं, पिछोला झील से थोड़ी ही पैदल दूरी पर।
क्या खाएँ
किसी घरेलू थाली वाली जगह पर दाल बाटी चूरमा, और नाश्ते में जगदीश मंदिर के पास कचौरी।
उदयपुर में एक वीकेंड
लेखक: मीरा अय्यर · 6 मिनट में पढ़ें
झीलें, महल और छत पर डिनर: पुराने शहर के लिए दो दिन काफ़ी हैं, अगर आप सुबहें सोच-समझकर बिताएँ।
कैसे पहुँचें
ट्रेन से
दिल्ली से रात भर चलने वाली ट्रेनें सुबह-सुबह उदयपुर सिटी स्टेशन पहुँचती हैं।
हवाई जहाज़ से
हवाई अड्डा पुराने शहर से क़रीब 22 किमी दूर है, टैक्सी से 40 मिनट का रास्ता।
कहाँ ठहरें
हवेली गेस्टहाउस गणगौर घाट के पास हैं, पिछोला झील से थोड़ी ही पैदल दूरी पर।
क्या खाएँ
किसी घरेलू थाली वाली जगह पर दाल बाटी चूरमा, और नाश्ते में जगदीश मंदिर के पास कचौरी।
जावास्क्रिप्ट के बिना डेमो उतना ही काम करता है जितना उसका एचटीएमएल; इंस्पेक्टर के लिए जावास्क्रिप्ट चाहिए।
कीबोर्ड
जिन कुंजियों पर यह काम करता है
हर क्रिया पॉइंटर के बिना काम करती है।
कुंजी
यह क्या करती है
Tab
पहले "ढाँचा दिखाएँ" पर, फिर हेडिंग की सूची से होते हुए ले जाता है।
EnterयाSpace
हेडिंग की सूची की किसी प्रविष्टि पर, फ़ोकस लेख में उस हेडिंग पर ले जाता है; अगला Tab वहीं से आगे बढ़ता है।
Space
"ढाँचा दिखाएँ" पर, लेख की हर हेडिंग पर उसका स्तर लिख देता है, और उस मोटे टेक्स्ट को चिह्नित करता है जो सिर्फ़ हेडिंग जैसा दिखता है।
Hया1या2या3
ये स्क्रीन रीडर की कुंजियाँ हैं, पेज की नहीं: NVDA और JAWS में H अगली हेडिंग पर, और कोई अंक उस स्तर की अगली हेडिंग पर ले जाता है। इनके लिए बस मार्कअप चाहिए।
स्क्रीन रीडर
यह क्या घोषित करता है
मार्कअप की भूमिकाओं, नामों और स्थितियों से लिखा गया।
कब
अपेक्षित घोषणा
सूची में H3 कैसे पहुँचें पर Enter
कैसे पहुँचें, हेडिंग, स्तर 3
स्क्रीन रीडर हेडिंग की सूची दिखाता है
उदयपुर में एक वीकेंड, स्तर 2; कैसे पहुँचें, स्तर 3; ट्रेन से, स्तर 4; हवाई जहाज़ से, स्तर 4; कहाँ ठहरें, स्तर 3; क्या खाएँ, स्तर 3
बिगड़ा हुआ संस्करण: सूची "कैसे पहुँचें" पर पहुँचती है
H4 कैसे पहुँचें, स्तर 2 से सीधे 4 पर, बटन
बिगड़ा हुआ संस्करण: स्क्रीन रीडर "ट्रेन से" पढ़ता है
ट्रेन से (सादा टेक्स्ट: H इसे लाँघ जाता है, और यह हेडिंग की सूची में नहीं है)
"ढाँचा दिखाएँ" चालू किया जाता है
ढाँचा दिखाएँ, स्विच, चालू (चेक किया हुआ)
ये अपेक्षित घोषणाएँ हैं, रिकॉर्डिंग नहीं।स्क्रीन रीडर और ब्राउज़र के हिसाब से शब्द और क्रम बदलते हैं।
कोड
कोड कॉपी करें
वही फ़ाइलें जिन पर यह डेमो चलता है।स्टाइल एक प्रीफ़िक्स के साथ परोसी जाती हैं जो इस साइट की अपनी स्टाइल को डेमो से दूर रखता है; आप जो कॉपी करते हैं वह मूल है।
मार्कअप
<div class="ap-hd" data-ap-headings>
<div class="ap-hd__rotor">
<button type="button" class="ap-hd__switch" role="switch" aria-checked="false" data-hd-structure>
<span class="ap-hd__track" aria-hidden="true"><span class="ap-hd__knob"></span></span>
Show structure
</button>
<div class="ap-hd__rotor-top">
<p class="ap-hd__rotor-name" id="hd-rotor-name">Headings</p>
<p class="ap-hd__count"><span data-hd-count>0</span> <span>found</span></p>
</div>
<p class="ap-hd__context"><span class="ap-hd__lvl" translate="no">H1</span> <span>This page's own name, above the demo</span></p>
<ol class="ap-hd__list" role="list" aria-labelledby="hd-rotor-name" data-hd-list></ol>
<div class="ap-hd__fakes" data-hd-fakes hidden>
<p class="ap-hd__fakes-name" id="hd-fakes-name">Looks like a heading, but is not</p>
<ul class="ap-hd__fake-list" role="list" aria-labelledby="hd-fakes-name" data-hd-fake-list></ul>
</div>
<p class="ap-hd__verdict" data-hd-verdict>
<svg class="ap-hd__verdict-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ap-hd__ok" d="m5 12 5 5L20 7"/><path class="ap-hd__bad" d="M12 8v5m0 3.5v.5"/></svg>
<span data-hd-verdict-text>Every level follows the one before it.</span>
<span data-hd-problems hidden></span>
</p>
</div>
<article class="ap-hd__article" data-hd-good>
<h2 class="ap-hd__h2">A weekend in Udaipur</h2>
<p class="ap-hd__byline">By Meera Iyer · 6 min read</p>
<p>Lakes, palaces and rooftop dinners: two days are enough for the old city, if you plan the mornings.</p>
<h3 class="ap-hd__h3">Getting there</h3>
<h4 class="ap-hd__h4">By train</h4>
<p>Overnight trains from Delhi reach <a href="#hd-station">Udaipur City station</a> early in the morning.</p>
<h4 class="ap-hd__h4">By air</h4>
<p>The airport is about 22 km from the old city, a 40-minute taxi ride.</p>
<h3 class="ap-hd__h3">Where to stay</h3>
<p><a href="#hd-havelis">Haveli guesthouses</a> near Gangaur Ghat are a short walk from Lake Pichola.</p>
<h3 class="ap-hd__h3">What to eat</h3>
<p>Dal baati churma at a family thali place, and kachori near Jagdish Temple for breakfast.</p>
</article>
<!-- The broken version, for comparison only: the same classes, so it
looks the same, but the tags are wrong. Do not copy this one. -->
<article class="ap-hd__article" data-hd-broken hidden>
<h2 class="ap-hd__h2">A weekend in Udaipur</h2>
<h5 class="ap-hd__byline">By Meera Iyer · 6 min read</h5>
<p>Lakes, palaces and rooftop dinners: two days are enough for the old city, if you plan the mornings.</p>
<h4 class="ap-hd__h3">Getting there</h4>
<p class="ap-hd__h4"><b>By train</b></p>
<p>Overnight trains from Delhi reach <a href="#hd-station">Udaipur City station</a> early in the morning.</p>
<p class="ap-hd__h4"><b>By air</b></p>
<p>The airport is about 22 km from the old city, a 40-minute taxi ride.</p>
<h3 class="ap-hd__h3">Where to stay</h3>
<p><a href="#hd-havelis">Haveli guesthouses</a> near Gangaur Ghat are a short walk from Lake Pichola.</p>
<h3 class="ap-hd__h3">What to eat</h3>
<p>Dal baati churma at a family thali place, and kachori near Jagdish Temple for breakfast.</p>
</article>
</div>
/**
* Heading structure: an article whose heading levels follow its outline,
* a headings list built from the markup (like a screen reader's) that moves
* focus to each heading and flags what is wrong, and a switch that labels
* every heading with its level on screen.
*
* Markup: [data-ap-headings] holding article[data-hd-good] (and, for the
* demo's comparison, article[data-hd-broken]), a list ol[data-hd-list], a
* count [data-hd-count], a group [data-hd-fakes] with ul[data-hd-fake-list],
* a verdict [data-hd-verdict] and a button[role=switch][data-hd-structure].
* Add data-broken to the root to show the broken article instead.
*/
const HEADINGS = "h1, h2, h3, h4, h5, h6, [role=heading]";
const PAGE_LEVEL = 1; // the page's own h1 sits above the demo
const levelOf = (el) => Number(el.getAttribute("aria-level")) || Number(el.localName.slice(1)) || 2;
/** Text as a screen reader gets it: parts marked aria-hidden left out. */
function textOf(node) {
let out = "";
for (const child of node.childNodes) {
if (child.nodeType === 3) out += child.data;
else if (child.nodeType === 1 && child.getAttribute("aria-hidden") !== "true") out += textOf(child);
}
return out.replace(/\s+/g, " ").trim();
}
function span(className, text, raw = false) {
const s = document.createElement("span");
s.className = className;
s.textContent = text;
if (raw) s.setAttribute("translate", "no");
return s;
}
export function init(root) {
const list = root.querySelector("[data-hd-list]");
const count = root.querySelector("[data-hd-count]");
const fakes = root.querySelector("[data-hd-fakes]");
const fakeList = root.querySelector("[data-hd-fake-list]");
const verdict = root.querySelector("[data-hd-verdict]");
const verdictText = root.querySelector("[data-hd-verdict-text]");
const problems = root.querySelector("[data-hd-problems]");
const toggle = root.querySelector("[data-hd-structure]");
const good = root.querySelector("[data-hd-good]");
const broken = root.querySelector("[data-hd-broken]");
const tabbed = new Set();
let found = [];
let lookalikes = [];
// The option: show the broken article in place of the good one.
const showBroken = root.hasAttribute("data-broken") && broken;
good.hidden = !!showBroken;
if (broken) broken.hidden = !showBroken;
const article = showBroken ? broken : good;
/* What a reviewer checks, read from the live page. */
function scan() {
const bodySize = parseFloat(getComputedStyle(article).fontSize);
found = [];
for (const el of article.querySelectorAll(HEADINGS)) {
const level = levelOf(el);
const issues = [];
// A level may go one deeper than the nearest heading above it, no more.
const parent = [...found].reverse().find((h) => h.level < level);
const from = parent ? parent.level : PAGE_LEVEL;
if (level > from + 1) issues.push(`Level jumps from ${from} to ${level}`);
if (!textOf(el)) issues.push("Empty heading");
if (parseFloat(getComputedStyle(el).fontSize) < bodySize) issues.push("Smaller than the body text: is it here for its size?");
found.push({ el, level, name: textOf(el), issues });
}
// Bold lines that look like headings but are paragraphs.
lookalikes = [...article.querySelectorAll("p")].filter((p) => {
const only = p.children.length === 1 ? p.firstElementChild : null;
return only && /^(b|strong)$/i.test(only.localName) && textOf(only) && textOf(only) === textOf(p);
});
}
function render() {
list.replaceChildren();
found.forEach((h, i) => {
const li = document.createElement("li");
li.className = "ap-hd__entry";
li.dataset.level = String(h.level);
const button = document.createElement("button");
button.type = "button";
button.className = "ap-hd__jump";
button.dataset.hdIndex = String(i);
const lvl = span(`ap-hd__lvl${h.issues.length ? " ap-hd__lvl--bad" : ""}`, `H${h.level}`, true);
button.append(lvl, span("ap-hd__entry-name", h.name));
for (const issue of h.issues) button.append(span("ap-hd__issue", issue));
li.append(button);
list.append(li);
});
count.textContent = String(found.length);
fakeList.replaceChildren();
for (const p of lookalikes) {
const li = document.createElement("li");
li.className = "ap-hd__fake";
li.append(span("ap-hd__lvl ap-hd__lvl--bad", "p", true), span("", textOf(p)));
fakeList.append(li);
}
fakes.hidden = lookalikes.length === 0;
const total = found.reduce((n, h) => n + h.issues.length, 0) + lookalikes.length;
verdict.dataset.state = total ? "bad" : "ok";
verdictText.textContent = total ? "Problems found:" : "Every level follows the one before it.";
problems.hidden = !total;
problems.textContent = total ? String(total) : "";
}
/* Show structure: a level badge inside each heading, hidden from assistive technology. */
function paintStructure(on) {
for (const tag of article.querySelectorAll(".ap-hd__tag")) tag.remove();
if (!on) return;
for (const h of found) {
const tag = span(`ap-hd__lvl ap-hd__tag${h.issues.length ? " ap-hd__lvl--bad" : ""}`, `H${h.level}`, true);
tag.setAttribute("aria-hidden", "true");
h.el.prepend(tag);
}
for (const p of lookalikes) {
const tag = span("ap-hd__lvl ap-hd__lvl--bad ap-hd__tag ap-hd__tag--fake", "Not a heading");
tag.setAttribute("aria-hidden", "true");
p.prepend(tag);
}
}
function jump(el) {
if (!el.hasAttribute("tabindex")) {
el.setAttribute("tabindex", "-1");
tabbed.add(el);
}
el.focus();
el.classList.remove("is-landed");
void el.offsetWidth; // restart the highlight
el.classList.add("is-landed");
}
function onClick(event) {
const entry = event.target.closest(".ap-hd__jump");
if (entry && list.contains(entry)) {
const h = found[Number(entry.dataset.hdIndex)];
if (h) jump(h.el);
return;
}
if (event.target.closest("[data-hd-structure]") === toggle) {
const on = toggle.getAttribute("aria-checked") !== "true";
toggle.setAttribute("aria-checked", String(on));
paintStructure(on);
}
}
// tabindex="-1" only for the jump: a later click should not focus the heading.
function onFocusOut(event) {
if (tabbed.has(event.target)) {
event.target.removeAttribute("tabindex");
tabbed.delete(event.target);
}
}
function onAnimationEnd(event) {
event.target.classList.remove("is-landed");
}
scan();
render();
paintStructure(toggle.getAttribute("aria-checked") === "true");
root.addEventListener("click", onClick);
article.addEventListener("focusout", onFocusOut);
article.addEventListener("animationend", onAnimationEnd);
return () => {
root.removeEventListener("click", onClick);
article.removeEventListener("focusout", onFocusOut);
article.removeEventListener("animationend", onAnimationEnd);
paintStructure(false);
for (const el of tabbed) el.removeAttribute("tabindex");
list.replaceChildren();
fakeList.replaceChildren();
};
}
for (const root of document.querySelectorAll("[data-ap-headings]")) init(root);
स्क्रीन रीडर इस्तेमाल करने वाले एक हेडिंग से दूसरी पर जाकर वह लाँघ जाते हैं जिसकी उन्हें ज़रूरत नहीं; डब्ल्यूसीएजी ब्लॉक लाँघने की जो तकनीकें बताता है, यह उनमें से एक है।
"ढाँचा दिखाएँ" role=switch और aria-checked वाला बटन है, इसलिए उसका नाम, भूमिका और चालू या बंद स्थिति सामने आती है।
उपयोग
इसे कब इस्तेमाल करें
इसे अपनाएँ
एक से ज़्यादा सेक्शन वाला कोई भी पेज: लेख, सेटिंग पेज, प्रोडक्ट पेज, सहायता पेज।
सेक्शन शुरू करने वाले कंपोनेंट, जैसे कार्डों का समूह या डायलॉग: उन्हें उसी स्तर की हेडिंग दें जहाँ वे रखे गए हैं।
कुछ और इस्तेमाल करें
ऐसा टेक्स्ट जो कोई सेक्शन शुरू नहीं करता, जैसे लेखक का नाम, क़ीमत या टैगलाइन, चाहे वह कितना भी बड़ा या छोटा दिखे।
लंबी सूची के हर कार्ड के लिए हेडिंग, जब लोग सिर्फ़ सूची पर ही सीधे पहुँचना चाहते हैं।
आम विफलताएँ
आमतौर पर यह कहाँ गलत होता है
दिखावट के लिए स्तर छोड़ना
h2 से सीधे h4 पर जाना, क्योंकि h4 का आकार पसंद आया, रूपरेखा तोड़ देता है। स्तर जगह के हिसाब से चुनें और आकार क्लास से तय करें।
हेडिंग की जगह मोटा टेक्स्ट
मोटे अक्षरों वाला पैराग्राफ़ हेडिंग जैसा दिखता है पर सादे टेक्स्ट की तरह पढ़ा जाता है और हेडिंग की सूची में कभी नहीं आता, इसलिए H से आगे बढ़ने वालों से उसका पूरा सेक्शन छिप जाता है।
आकार के लिए चुनी गई हेडिंग
h5 में लेखक का नाम या h2 में क़ीमत हेडिंग की सूची में शोर भरते हैं। अगर वह कोई सेक्शन शुरू नहीं करता, तो वह क्लास वाला पैराग्राफ़ है।
कंपोनेंट के अंदर तय स्तर
जो कार्ड हमेशा h3 बनाता है, वह कहीं और h4 के नीचे पहुँच जाता है। कंपोनेंट को जो रखे, स्तर वही चुने।
ख़ाली या सिर्फ़ आइकन वाली हेडिंग
बिना टेक्स्ट की, या सिर्फ़ आइकन वाली हेडिंग को बस "हेडिंग स्तर 3" बोला जाता है, और कुछ नहीं। हर हेडिंग में शब्द चाहिए।
h1 नहीं, या कई
पेज का नाम एक h1 में होना चाहिए। पेज में रखे गए कंपोनेंट अपना h1 साथ न लाएँ।
नोट्स
इसे बनाना
लेख h2 से शुरू होता है क्योंकि इस पेज का अपना नाम उसका h1 है। अपने पेज पर वहीं से शुरू करें जहाँ सामग्री है: पेज के नाम के लिए एक h1, मुख्य सेक्शन के लिए h2, और इसी तरह नीचे।
स्टाइल क्लास से दें, टैग से नहीं: बिगड़ा हुआ संस्करण वही क्लास इस्तेमाल करता है, इसलिए दोनों एक जैसे दिखते हैं और सिर्फ़ टैग अलग हैं, और इसी वजह से गड़बड़ियाँ नज़र नहीं आतीं।
हेडिंग की सूची मार्कअप से वैसे ही बनती है जैसे स्क्रीन रीडर अपनी सूची बनाता है, और वही जाँचती है जो कोई समीक्षक जाँचता: सबसे पास की ऊँची हेडिंग से स्तर की छलाँग, बॉडी टेक्स्ट से छोटी हेडिंग, और हेडिंग जैसी दिखने वाली मोटी पंक्तियाँ।
हेडिंग पर aria-level सिर्फ़ बोली जाने वाली बात बदलता है। इसके बजाय एलिमेंट बदलें, ताकि पेज, रूपरेखा और स्टाइल एक-दूसरे से मेल खाएँ।
सूची से पहुँची हेडिंग को tabindex="-1" सिर्फ़ छलाँग के लिए मिलता है, ताकि बाद में उस पर क्लिक करने से फ़ोकस रिंग न बने।
लाइट और डार्क थीम में, डेस्कटॉप और फ़ोन की चौड़ाई पर axe से और कीबोर्ड से जाँचा गया।अभी हर स्क्रीन रीडर और ब्राउज़र जोड़ी के साथ नहीं परखा गया।सुधार बताएँ