CKTIS / HTML
aria-pressed — a persistent toggle-button state
`aria-pressed` distinguishes a toggle button from an ordinary button that performs a one-off command.
Version: WAI-ARIA 1.2
Syntax
<button aria-pressed="false">Bold</button>On a button use true, false, or mixed. An absent state denotes an ordinary button. Mixed can describe inconsistent settings in a group, not a key being physically held down.
Keep a stable name such as Bold, and separately update state and visible effect. A native button provides basic keyboard activation, but ARIA supplies no toggle logic or styling. Do not substitute this property for a checkbox’s checked state.
The example changes text weight and button state in one function. The test verifies pressed state in the accessibility tree and computed font weight 700. It therefore demonstrates both the assistive-technology description and a real visual change.
Examples
<!doctype html><meta charset="utf-8">
<style>.bold {font-weight:700} #sample:not(.bold) {font-weight:400}</style>
<button id="bold" aria-pressed="false">Bold</button><p id="sample">Selected text</p>
<output id="result"></output>
<script>
const button = document.querySelector('#bold'), sample = document.querySelector('#sample');
button.addEventListener('click', () => {
const pressed = button.getAttribute('aria-pressed') !== 'true';
button.setAttribute('aria-pressed', String(pressed)); sample.classList.toggle('bold', pressed);
});
button.click();
document.querySelector('#result').textContent = 'pressed=' + button.getAttribute('aria-pressed') + '; weight=' + getComputedStyle(sample).fontWeight;
</script>Result
pressed=true; weight=700
The result is enabled bold formatting. Another activation reverses the state while keeping the same name.