CKTIS / HTML
aria-selected — selection in a composite widget
`aria-selected` describes selection of an item such as a tab, option, or interactive cell according to its role.
Version: WAI-ARIA 1.2
Syntax
<button role="tab" aria-selected="true">Preview</button>Use true or false on roles that support selection. Absence may mean an item is not selectable. This is neither the current page nor focus itself: aria-current has a different meaning.
For multiple selection also configure the container’s selection model. The state alone selects no data, hides no panels, and manages no keyboard behavior. Update appearance, focus, and selection according to the chosen pattern without automatically equating them.
The tab example activates Preview, updates both states, and changes panel visibility. An arrow moves focus without changing selection; activation is separate. The test verifies the accessibility tree, panels, and that distinction between focus and selection.
Examples
<!doctype html><meta charset="utf-8">
<div role="tablist" aria-label="Editor views">
<button id="edit" role="tab" aria-selected="true" aria-controls="editor">Edit</button>
<button id="view" role="tab" aria-selected="false" aria-controls="preview" tabindex="-1">Preview</button></div>
<section id="editor" role="tabpanel" aria-labelledby="edit">Editor content</section>
<section id="preview" role="tabpanel" aria-labelledby="view" hidden>Preview content</section>
<output id="result"></output>
<script>
const tabs = [...document.querySelectorAll('[role=tab]')];
tabs.forEach((tab, i) => {
tab.addEventListener('click', () => tabs.forEach(other => {
const selected = other === tab;
other.setAttribute('aria-selected', String(selected)); other.tabIndex = selected ? 0 : -1;
document.getElementById(other.getAttribute('aria-controls')).hidden = !selected;
}));
tab.addEventListener('keydown', event => {
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
event.preventDefault(); tabs[1 - i].focus();
}
});
});
document.querySelector('#view').click();
document.querySelector('#result').textContent = 'selected=' + document.querySelector('[aria-selected=true]').textContent + '; firstHidden=' + document.querySelector('#editor').hidden + '; secondHidden=' + document.querySelector('#preview').hidden;
</script>Result
selected=Preview; firstHidden=true; secondHidden=false
This uses manual tab activation. Arrows move focus; clicking or activating the button changes the panel.