• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Supporting Accessibility
2
3## Overview
4
5ArkUI provides comprehensive accessibility capabilities, enabling you to create accessible application UIs that meet the needs of users with visual, auditory, motor, and cognitive impairments.
6
7When the [accessibility attributes](../reference/apis-arkui/arkui-ts/ts-universal-attributes-accessibility.md) of a component change, it triggers responses such as screen readers re-reading component information, accessibility services rescanning the component tree, state announcements, and dynamic updates of virtual nodes. These mechanisms ensure that assistive tools (such as screen readers) can promptly perceive and adapt to changes, providing a consistent experience for users with disabilities.
8
9## Setting Accessibility Groups
10
11The **accessibilityGroup** attribute sets whether to enable accessibility grouping. If this feature is enabled, the component and all its child components are treated as a whole, and accessibility services no longer process child components individually. The **accessibilityGroup** attribute supports the following values:
12
13- **false** (default): Accessibility grouping is disabled.
14
15- **true**: Accessibility grouping is enabled.
16
17Here is an example using the **Column** component to enable accessibility grouping:
18
19```ts
20Column() {
21}
22.accessibilityGroup(true)
23```
24
25## Setting the Accessibility Level
26
27The **accessibilityLevel** attribute indicates the accessibility level of a component, controlling whether it can be recognized by accessibility services. It supports the following values:
28
29- **"auto"** (default): The component's recognizability is determined by the accessibility grouping service and ArkUI.
30
31- **"yes"**: The component can be recognized by accessibility services.
32
33- **"no"**: The component cannot be recognized by accessibility services.
34
35- **"no-hide-descendants"**: Neither the component nor its child components can be recognized by accessibility services.
36
37Here is an example using the **Column** component to set its accessibility level to **"yes"**:
38
39```ts
40Column() {
41}
42.accessibilityGroup(true)
43.accessibilityLevel("yes")
44```
45
46## Setting the Accessibility Text
47
48The **accessibilityText** attribute provides readable text for components without text content. If a component already has text, the accessibility text takes precedence during announcement.
49
50This attribute supports strings or resource references.
51
52Here is an example using the **Column** component to set its accessibility text to **"Group"**:
53
54```ts
55Column() {
56}
57.accessibilityGroup(true)
58.accessibilityLevel("yes")
59.accessibilityText("Group")
60```
61
62## Setting Accessibility Description
63
64The **accessibilityDescription** attribute provides a more detailed description of the component, which is read after the text content.
65
66Here is an example using the **Column** component to set its accessibility description:
67
68```ts
69Column() {
70}
71.accessibilityGroup(true)
72.accessibilityLevel("yes")
73.accessibilityText("Group")
74.accessibilityDescription("The Column component can be selected, and the announced content is 'Group'")
75```
76
77## Setting Accessibility Virtual Nodes
78
79The **accessibilityVirtualNode** attribute adds virtual accessibility nodes to self-drawn components. Assistive tools read information from these nodes instead of the actual displayed content.
80
81```ts
82@Entry
83@Component
84struct VirtualNodeExample {
85  @Builder customAccessibilityNode() {
86    Text("Text 2")
87      .fontSize(50)
88      .fontWeight(FontWeight.Bold)
89  }
90
91  build() {
92    Column() {
93      Text("Text 1")
94        .fontSize(50)
95        .fontWeight(FontWeight.Bold)
96    }
97    .accessibilityGroup(true)
98    .accessibilityLevel("yes")
99    .accessibilityVirtualNode(this.customAccessibilityNode)
100  }
101}
102```
103
104## Setting Whether an Accessibility Node Is Selected
105
106The **accessibilityChecked** and **accessibilitySelected** attributes enhance accessibility by communicating the selection state of components to assistive tools like screen readers.
107
108### Setting Selection State for Multi-Select Scenarios
109
110The **accessibilityChecked** attribute indicates whether a component is checked in multi-select scenarios (for example, check boxes and toggle buttons). It applies to scenarios requiring clear "selected/unselected" semantics and supports the following values:
111
112- **undefined** (default): automatically determined by the system (depending on the component's own state, such as the **isOn** attribute of a **Toggle** component).
113
114- **false**: not selected.
115
116- **true**: selected (for example, check box checked).
117
118Here is an example using the **Column** component to set it as checked when multi-select is supported:
119
120```ts
121Column() {
122}
123.accessibilityGroup(true)
124.accessibilityLevel("yes")
125.accessibilityText("Group")
126.accessibilityDescription("The Column component can be selected, and the announced content is 'Group'")
127.accessibilityChecked(true)
128```
129
130### Setting Selection State for Single-Select Scenarios
131
132The **accessibilitySelected** attribute indicates whether a component is selected in single-select scenarios (for example, single-select lists and tabs). It applies to scenarios requiring differentiation of "current selected items" (for example, single-select groups and navigation menus) and supports the following values:
133
134- **undefined** (default): automatically determined by the system.
135
136- **false**: not selected.
137
138- **true**: currently selected.
139
140Here is an example using the **Column** component to let the system determine its selection state when single-select is supported:
141
142```ts
143Column() {
144}
145.accessibilityGroup(true)
146.accessibilityLevel("yes")
147.accessibilityText("Group")
148.accessibilityDescription("The Column component can be selected, and the announced content is 'Group'")
149.accessibilitySelected(undefined)
150```
151
152### Key Differences Between accessibilityChecked and accessibilitySelected
153
154In ArkUI accessibility attributes, both **accessibilityChecked** and **accessibilitySelected** are used to indicate the state of a component, but they have fundamentally different application scenarios and semantic meanings. The following table provides a comparison of these two.
155
156| Attribute   | accessibilityChecked     | accessibilitySelected |
157| ------- | ------------------------ | --------------------- |
158| Use cases| Binary or ternary components, such as check boxes and toggles.| Mutually exclusive selection scenarios, such as single-select lists and tabs.|
159| Semantic objectives| Physical state of components (for example, whether a switch is on).| Navigation focus item (for example, current selected item in a list).|
160| State persistence| Usually requires explicit saving (such as form submission).| Temporary (changes with focus movement).|
161| Typical components| **Checkbox** and **Toggle**.        | **List** and **Tabs**.       |
162
163## Recommendations
164
165- Priority control
166
167  Use **accessibilityLevel** to ensure key operations are recognizable.
168
169- Semantic descriptions
170
171  Add **accessibilityText** and **accessibilityDescription** for non-text elements like icons and images.
172
173- Grouping optimization
174
175  Use **accessibilityGroup** to reduce redundant announcements for complex layouts.
176
177## Scenario Example
178
179This example demonstrates how to use **accessibilityText** and **accessibilityDescription** to customize the content announced by screen readers.
180
181If a component has both text and accessibility text attributes, only the accessibility text is announced when the component is selected.
182
183```ts
184@Entry
185@Component
186struct Index {
187
188  @Builder customAccessibilityNode() {
189    Column() {
190      Text(`virtual node`)
191    }
192    .width(10)
193    .height(10)
194  }
195
196  build() {
197    Row() {
198      Column() {
199        Text("Text 1")
200          .fontSize(50)
201          .fontWeight(FontWeight.Bold)
202        Text("Text 2")
203          .fontSize(50)
204          .fontWeight(FontWeight.Bold)
205      }
206      .width('100%')
207      .accessibilityGroup(true)
208      .accessibilityLevel("yes")
209      .accessibilityText("Group")
210      .accessibilityDescription("The Column component can be selected, and the announced content is 'Group'")
211      .accessibilityVirtualNode(this.customAccessibilityNode)
212      .accessibilityChecked(true)
213      .accessibilitySelected(undefined)
214    }
215    .height('100%')
216  }
217}
218```
219
220![en-us_image_0000001745415556](figures/en-us_image_0000001745415556.jpg)
221