0Pricing
Web Accessibility Academy · 课时

角色定义事物的性质

告知辅助技术某个元素是选项卡、警报还是对话框。

角色定义事物的性质 是 CoddyKit 上的免费 Web Accessibility Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web Accessibility Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web Accessibility Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

A Role Is an Identity

A role tells assistive tech the kind of thing an element is: a button, a tab, an alert, a dialog. It answers what is this?

Native Elements Have Roles Already

Most HTML tags carry an implicit role built in. A nav is a navigation, an h1 is a heading, a button is a button.

<nav>...</nav>
<!-- implicit role: navigation -->

The role Attribute

When no native tag fits, you set the role attribute by hand to give a generic element a recognized identity.

<div role="alert">Saved!</div>

Widget Roles

Widget roles describe interactive things you sometimes build by hand: tab, slider, switch, menuitem, and treeitem.

Landmark Roles

Landmark roles map the page into regions like banner, main, and navigation so users can jump straight to a section.

Document Structure Roles

Structure roles describe static content: heading, list, listitem, and figure. They label the shape of your information.

One Role Per Element

An element gets one role. You cannot make something a button and a link at once, so pick the identity that matches its real job.

Roles Imply Requirements

Choosing a role is a contract. role=tab means you owe it a tablist parent, keyboard support, and a linked tabpanel.

<div role="tab" aria-selected="true">Profile</div>

Do Not Override Good Semantics

Never put a role on an element that already has the right one. A redundant role on a real button just adds noise and risk.

<button role="button">Save</button>
<!-- the role is pointless here -->

role=presentation Erases Meaning

role=presentation strips an element of its semantics. Useful for a layout table, dangerous on anything users need to understand.

Roles Are the Foundation

Get the role right first. States and properties only make sense once the element has a clear identity to attach them to.

Quick Check

You wrap a custom popup that interrupts the user in a div. Which role fits?

Recap: Roles First

You learned a role names what an element is. Prefer native implicit roles, add one explicit role only when needed, and honor its contract.

常见问题解答

「角色定义事物的性质」课时是免费的吗?

是的 — 「角色定义事物的性质」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web Accessibility Academy 课程的其余内容,请升级到 CoddyKit PRO。 Web Accessibility Academy 课程共包含 4 节课。

「角色定义事物的性质」这节课中我会学到什么?

告知辅助技术某个元素是选项卡、警报还是对话框。 你通过在浏览器中直接运行的动手代码来练习 Web Accessibility Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Web Accessibility Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Web Accessibility Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「角色定义事物的性质」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Web Accessibility Academy 课中编写并运行代码吗?

能。每节 Web Accessibility Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 第一原则:没有 ARIA 胜过糟糕的 ARIA
  2. 角色定义事物的性质
  3. 状态与属性:展开、选中、禁用
  4. 读取无障碍树来调试 ARIA
← 返回 Web Accessibility Academy