aria-hiddenとaria-live
装飾要素を隠し、動的コンテンツをスクリーンリーダーに通知します
「aria-hiddenとaria-live」はCoddyKit上の無料HTML Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはHTML Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 HTML Academyコースには全4レッスンが含まれています。
aria-hidden
aria-hidden="true" は要素をアクセシビリティツリーから除外するため、スクリーンリーダーはその要素を完全に読み飛ばします。
<!-- Decorative icon: visible but skip by screen readers -->
<span aria-hidden="true">★★★★☆</span>
<span class="sr-only">4 out of 5 stars</span>
<!-- Decorative separator -->
<img src="divider.svg" alt="" aria-hidden="true">
<!-- Note: aria-hidden does NOT affect visibility or tab focus
A button with aria-hidden is still tabbable! -->aria-hiddenの使用例
aria-hiddenの適切な使用例:
<!-- 1. Icons next to descriptive text -->
<button>
<svg aria-hidden="true"><!-- icon --></svg>
Save Document
</button>
<!-- 2. Repeated text in a card link -->
<a href="/blog/post-1">
<span aria-hidden="true">Read more</span>
<span class="sr-only">Read more: HTML5 Forms Guide</span>
</a>
<!-- 3. UI decoration (dots, decorative borders) -->
<span aria-hidden="true">•••</span>aria-hiddenの注意点
フォーカス可能な要素には、決してaria-hiddenを適用しないでください。
<!-- BAD: button is in tab order but invisible to screen readers -->
<button aria-hidden="true">Close</button>
<!-- Users reach this via Tab but hear nothing
They cannot tell if they're on a button or lost focus -->
<!-- If you want to hide from both: use hidden attribute -->
<button hidden>Close</button>
<!-- Or: disabled (but disabled removes from tab order) -->
<button disabled aria-hidden="true">Close</button>aria-live
aria-live を設定すると領域がライブリージョンになり、変更が自動的に読み上げられます。
<!-- polite: announce when user is idle -->
<div aria-live="polite" id="status"></div>
<!-- assertive: announce immediately, interrupting current speech -->
<div aria-live="assertive" id="errors"></div>
<script>
// Inject text to trigger announcement:
document.getElementById('status').textContent = 'File saved successfully.';
// Screen reader announces this without user moving focus
</script>aria-liveの値
aria-liveには次の3つの値があります:
off— デフォルト値:変更を読み上げませんpolite— ユーザーが操作を一時停止したときに読み上げます。緊急性のない更新に使用しますassertive— 直ちに読み上げ、現在の読み上げに割り込みます。エラーや重大なアラートに使用します
aria-atomic
aria-atomic は、領域全体を読み上げるか、変更された部分だけを読み上げるかを制御します。
<div aria-live="polite" aria-atomic="true" id="timer">
Time remaining: 05:00
</div>
<!-- aria-atomic="true": announce the whole div each update -->
<!-- Without it: only the changed text node is announced
'Time remaining: 05:00' vs just '05:00' -->
<script>
setInterval(() => {
document.getElementById('timer').textContent = `Time remaining: ${getTime()}`;
}, 1000);
</script>aria-relevant
aria-relevant は、どの種類の変更を読み上げるかを指定します。
<div
aria-live="polite"
aria-relevant="additions text" <!-- announce added content and text changes -->
id="feed"
>
<!-- New items added here -->
</div>
<!-- Values: additions, removals, text, all
Default: additions text
aria-relevant="removals" needed to announce deleted items -->ライブリージョンのベストプラクティス
ライブリージョンを使用する際のガイドライン:
- 通知の種類ごとに、常に存在するライブリージョンを1つ使用します(作成と破棄を繰り返さないでください)
- 最初は空にしておき、読み上げを発生させるためにテキストを挿入します
- 通知は簡潔にします。スクリーンリーダーは現在の読み上げに割り込んだり、読み上げが遅れたりすることがあります
- 読み込み状態にはpoliteを使用します
- フォームエラーにはassertiveまたはrole="alert"を使用します
トースト通知のパターン
ライブリージョンを使用してトースト通知を読み上げます:
<div
role="status"
aria-live="polite"
aria-atomic="true"
id="toast-container"
class="sr-only"
></div>
<script>
function showToast(message) {
const container = document.getElementById('toast-container');
container.textContent = '';
// Force rerender for re-announcement:
requestAnimationFrame(() => {
container.textContent = message;
});
}
</script>aria-busy
aria-busy="true" は、コンテンツが更新中であることを示します。
<div id="feed" aria-live="polite" aria-busy="false">
<!-- content -->
</div>
<script>
const feed = document.getElementById('feed');
feed.setAttribute('aria-busy', 'true');
await loadContent();
feed.innerHTML = newContent;
feed.setAttribute('aria-busy', 'false');
// Only now does the live region announce the update
</script>確認問題
aria-live="assertive"と"polite"は、それぞれいつ使用すべきですか?
まとめ:aria-hiddenとaria-live
非表示とライブリージョンの要点:
aria-hidden="true"— アクセシビリティツリーから除外します(フォーカス可能な要素には使用しません)aria-live="polite"— ユーザーが操作を停止したときに変更を読み上げますaria-live="assertive"— 直ちに変更を読み上げます(エラーに使用します)aria-atomic="true"— 変更時に領域全体を読み上げますaria-busy— 読み込み中の通知を抑制します
AI チューターと学ぶ HTML — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 40
- レッスン
- 159
よくある質問
「aria-hiddenとaria-live」レッスンは無料ですか?
はい。「aria-hiddenとaria-live」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、HTML Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 HTML Academyコースには全4レッスンが含まれています。
「aria-hiddenとaria-live」で何を学びますか?
装飾要素を隠し、動的コンテンツをスクリーンリーダーに通知します ブラウザで直接実行するハンズオンコードでHTML Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
HTML Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのHTML Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「aria-hiddenとaria-live」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このHTML Academyレッスンでコードを書いて実行できますか?
はい。すべてのHTML Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ARIAとネイティブHTMLの使い分け
- role button alert dialog landmark
- aria-label aria-labelledby aria-describedby
- aria-hiddenとaria-live