Шаблон вкладок: tablist, tab, tabpanel
Связывайте три роли, необходимые набору вкладок.
«Шаблон вкладок: tablist, tab, tabpanel» — бесплатный урок Web Accessibility Academy на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Web Accessibility Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Web Accessibility Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
What a Tab Set Really Is
A tab set shows one panel at a time and lets users switch between them. To assistive tech it must look like one widget, not loose links.
Three Roles Work Together
The pattern relies on three ARIA roles: a tablist that holds the tabs, each tab, and the panel each tab reveals. Get all three right.
The Container Is a tablist
Wrap your row of tabs in an element with role="tablist". This tells screen readers the children inside are a related set of tabs.
<div role="tablist">...</div>Each Tab Is a Button
Build each tab from a real button with role="tab". A button is focusable and clickable for free, so you avoid extra wiring.
<button role="tab">Profile</button>The Panel Is a tabpanel
The content each tab shows gets role="tabpanel". This marks it as the region controlled by the currently selected tab.
<div role="tabpanel">Profile details</div>Mark the Selected Tab
Set aria-selected="true" on the active tab and false on the rest. Screen readers announce which tab is currently chosen.
<button role="tab" aria-selected="true">Profile</button>Link Tab to Its Panel
Point each tab at its panel with aria-controls, set to the panel id. Users learn which region the tab opens.
<button role="tab" aria-controls="p1">Profile</button>Name the Panel From Its Tab
Give the panel an aria-labelledby that points back to its tab. Now the panel borrows the tab text as its accessible name.
<div role="tabpanel" aria-labelledby="tab1">...</div>Hide the Inactive Panels
Only one panel should show at a time. Add the hidden attribute to the panels whose tab is not selected so they leave the page.
<div role="tabpanel" hidden>...</div>Give the Tablist a Label
A tablist deserves an aria-label describing its purpose, like Account settings. Users hear what the whole set of tabs is for.
<div role="tablist" aria-label="Account settings">...</div>How It All Sounds
Put together, a screen reader announces something like Profile, tab, selected, 1 of 3. That orientation is exactly what makes tabs usable.
Quick Check
You are wiring up the container that holds your row of tabs. Which role belongs on it?
Recap: The Tabs Pattern
You learned the tablist, tab, tabpanel trio. Mark the selected tab, link each tab to its panel, and hide the inactive ones.
Часто задаваемые вопросы
Урок «Шаблон вкладок: tablist, tab, tabpanel» бесплатный?
Да — полный текст урока «Шаблон вкладок: tablist, tab, tabpanel» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Web Accessibility Academy, подпишись на CoddyKit PRO. Курс Web Accessibility Academy содержит 4 уроков всего.
Чему я научусь в уроке «Шаблон вкладок: tablist, tab, tabpanel»?
Связывайте три роли, необходимые набору вкладок. Ты практикуешь Web Accessibility Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Web Accessibility Academy?
Предыдущий опыт не требуется. Web Accessibility Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 1 из 4.
Сколько времени занимает урок «Шаблон вкладок: tablist, tab, tabpanel»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Web Accessibility Academy?
Да. Каждый урок Web Accessibility Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Шаблон вкладок: tablist, tab, tabpanel
- Навигация между вкладками стрелками
- Аккордеоны с Button и aria-expanded
- Раскрывающийся элемент или вкладки: выберите подходящий вариант