0Pricing
Web Accessibility Academy · レッスン

ダイアログロールとネイティブのdialog要素

レイヤーを本物のモーダルダイアログとして示します。

「ダイアログロールとネイティブのdialog要素」はCoddyKit上の無料Web Accessibility Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb Accessibility Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web Accessibility Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

What Makes a Dialog a Dialog

A dialog is a layer that interrupts the page to ask for input or show a message. Screen reader users need to be told it is a dialog, not just floating text.

A div Looks Modal but Is Not

A styled div can look like a popup, yet assistive tech sees ordinary content. Without the right role, users never learn a dialog opened.

<div class="modal">Are you sure?</div>

Meet the Native dialog Element

The HTML dialog element is built for this job. It carries dialog semantics for free, so screen readers announce it correctly.

<dialog>Are you sure?</dialog>

Open It as a True Modal

Call showModal() in JavaScript to open dialog as a real modal. This is what makes the page behind it inert and unreachable.

document.querySelector("dialog").showModal();

show() Is Not Modal

Watch out: show() opens the dialog as non-modal, so the page stays interactive behind it. For a blocking dialog, you want showModal().

dialog.show();

The role Behind dialog

Under the hood, the element maps to the dialog role. If you must build one from a div, role="dialog" is the attribute that gives it meaning.

<div role="dialog">Settings</div>

alertdialog for Urgent Choices

When a dialog demands a response, like a delete confirmation, use role="alertdialog". It signals extra urgency to assistive tech.

<div role="alertdialog">Delete this file?</div>

Every Dialog Needs a Name

A dialog must have an accessible name so users know its purpose on open. Point aria-labelledby at the heading inside it.

<dialog aria-labelledby="t"><h2 id="t">Confirm</h2></dialog>

Close It in Code

The native element offers a matching close() method. Calling it dismisses the dialog and lets the page behind become reachable again.

dialog.close();

The Built-In Backdrop

A modal dialog gets a free backdrop you can style with the ::backdrop pseudo-element. It dims the page and signals focus has shifted.

dialog::backdrop { background: rgba(0,0,0,0.5); }

Why Native Saves You Work

The native dialog handles focus, Escape, and inerting the background for you. Reaching for it means fewer bugs than a hand-rolled div.

Quick Check

You want a confirmation popup that blocks the page until the user responds. Which call should you use?

Recap: Use Real Dialogs

You learned a modal needs dialog semantics. Prefer the native dialog with showModal(), give it a name, and reserve alertdialog for urgent choices.

よくある質問

「ダイアログロールとネイティブのdialog要素」レッスンは無料ですか?

はい。「ダイアログロールとネイティブのdialog要素」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web Accessibility Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web Accessibility Academyコースには全4レッスンが含まれています。

「ダイアログロールとネイティブのdialog要素」で何を学びますか?

レイヤーを本物のモーダルダイアログとして示します。 ブラウザで直接実行するハンズオンコードでWeb Accessibility Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web Accessibility Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb Accessibility Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「ダイアログロールとネイティブのdialog要素」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb Accessibility Academyレッスンでコードを書いて実行できますか?

はい。すべてのWeb Accessibility Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ダイアログロールとネイティブのdialog要素
  2. モーダル内にフォーカスを閉じ込める
  3. Escapeで閉じてフォーカスを戻す
  4. 背景をinertにしてaria-modalを設定する
← Web Accessibility Academyに戻る