1e41f4b71Sopenharmony_ci# Universal Attributes
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  Universal attributes are supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Common Attributes
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciCommon attributes are used to set component identities and appearance.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci| Name                       | Type     | Default Value  | Mandatory  | Description                                      |
12e41f4b71Sopenharmony_ci| ------------------------- | ------- | ----- | ---- | ---------------------------------------- |
13e41f4b71Sopenharmony_ci| id                        | string  | -     | No   | Unique ID of the component.                                |
14e41f4b71Sopenharmony_ci| style                     | string  | -     | No   | Style declaration of the component.                                |
15e41f4b71Sopenharmony_ci| class                     | string  | -     | No   | Style class of the component, which is used to refer to a style table.                         |
16e41f4b71Sopenharmony_ci| ref                       | string  | -     | No   | Reference information of child elements or child components, which is registered with the parent component on `$refs`.|
17e41f4b71Sopenharmony_ci| disabled                  | boolean | false | No   | Whether the component is disabled. If it is disabled, it cannot respond to user interaction.           |
18e41f4b71Sopenharmony_ci| data                      | string  | -     | No   | Attribute set for the component to facilitate data storage and reading. In the JS file:<br>- Use **e.target.attr.data** to read data in the event callback, where **e** is the input parameter.<br>- Use `$element` or `$refs` to obtain a DOM element, which can then be accessed through **attr.data**.<br>You are advised to use **data-*** instead since API version 6.|
19e41f4b71Sopenharmony_ci| data-\*<sup>6+</sup>      | string  | -     | No   | Attribute set for the component to facilitate data storage and reading. The value is case insensitive. For example, **data-A** and **data-a** are the same by default. In the JS file:<br>- Use **e.target.dataSet.a** to read data in the event callback, where **e** is the input parameter.<br>- After a DOM element is obtained by using **$element** or **$refs**, it can be accessed through **dataSet.a**.|
20e41f4b71Sopenharmony_ci| click-effect<sup>5+</sup> | string  | -     | No   | Click effect complying with spring physics. Available values are as follows:<br>- **spring-small**: The component scales down to 90% of its size when it is selected. This is appropriate for small components.<br>- **spring-medium**: The component scales down to 95% of its size when it is selected. This is appropriate for medium-sized components.<br>- **spring-large**: The component scales down to 95% of its size when it is selected. This is appropriate for large components.|
21e41f4b71Sopenharmony_ci| dir<sup>6+</sup>          | string  | auto  | No   | Element layout mode. Available values are as follows:<br>- **rtl**: right-to-left layout.<br>- **ltr**: left-to-right layout.<br>- **auto**: follows the system language environment.|
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci## Rendering Attributes
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ciRendering attributes are used to set whether a component is rendered.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci| Name  | Type     | Default Value | Description                      |
29e41f4b71Sopenharmony_ci| ---- | ------- | ---- | ------------------------ |
30e41f4b71Sopenharmony_ci| for  | Array   | -    | Expands the current element based on the configured data list.       |
31e41f4b71Sopenharmony_ci| if   | boolean | -    | Whether the element is added or removed.|
32e41f4b71Sopenharmony_ci| show | boolean | -    | Whether the element is displayed or hidden.|
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci>  **NOTE**
35e41f4b71Sopenharmony_ci>
36e41f4b71Sopenharmony_ci>  Do not set styles in attribute fields.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci## Example
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci### Example 1
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci```html
43e41f4b71Sopenharmony_ci<!-- xxx.hml -->
44e41f4b71Sopenharmony_ci<div id="container">
45e41f4b71Sopenharmony_ci    <button class="btn" type="capsule" value="toggleDisplay" onclick="toggleDisplay"></button>
46e41f4b71Sopenharmony_ci	<list class="list">
47e41f4b71Sopenharmony_ci		<list-item for="{{ array }}" class="listItem">
48e41f4b71Sopenharmony_ci			<text class="text" onclick="toggleShow" show="{{ visible }}"
49e41f4b71Sopenharmony_ci                  if="{{ display }}">{{ $item.value }}</text>
50e41f4b71Sopenharmony_ci		</list-item>
51e41f4b71Sopenharmony_ci	</list>
52e41f4b71Sopenharmony_ci</div>
53e41f4b71Sopenharmony_ci```
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci```css
56e41f4b71Sopenharmony_ci/* xxx.css */
57e41f4b71Sopenharmony_ci#container {
58e41f4b71Sopenharmony_ci    flex-direction: column;
59e41f4b71Sopenharmony_ci    width: 100%;
60e41f4b71Sopenharmony_ci    margin-top: 10px;
61e41f4b71Sopenharmony_ci}
62e41f4b71Sopenharmony_ci.text {
63e41f4b71Sopenharmony_ci    font-size: 50px;
64e41f4b71Sopenharmony_ci    font-weight: 500;
65e41f4b71Sopenharmony_ci    margin-left: 12px;
66e41f4b71Sopenharmony_ci}
67e41f4b71Sopenharmony_ci.listItem {
68e41f4b71Sopenharmony_ci    width: 100%;
69e41f4b71Sopenharmony_ci    height: 100px;
70e41f4b71Sopenharmony_ci    line-height: 60px;
71e41f4b71Sopenharmony_ci    border-bottom: 1px solid #DEDEDE;
72e41f4b71Sopenharmony_ci    font-size: 20px;
73e41f4b71Sopenharmony_ci}
74e41f4b71Sopenharmony_ci.btn{
75e41f4b71Sopenharmony_ci    width: 280px;
76e41f4b71Sopenharmony_ci    font-size: 26px;
77e41f4b71Sopenharmony_ci    margin: 10px 0;
78e41f4b71Sopenharmony_ci}
79e41f4b71Sopenharmony_ci```
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci```js
82e41f4b71Sopenharmony_ci// xxx.js
83e41f4b71Sopenharmony_ciexport default {
84e41f4b71Sopenharmony_ci	data: {
85e41f4b71Sopenharmony_ci        visible: true,
86e41f4b71Sopenharmony_ci        display: true,
87e41f4b71Sopenharmony_ci        title: "",
88e41f4b71Sopenharmony_ci        i: 4,
89e41f4b71Sopenharmony_ci        array: [
90e41f4b71Sopenharmony_ci            {"value": "Item 0"},
91e41f4b71Sopenharmony_ci            {"value": "Item 1"},
92e41f4b71Sopenharmony_ci            {"value": "Item 2"},
93e41f4b71Sopenharmony_ci            {"value": "Item 3"},
94e41f4b71Sopenharmony_ci        ],
95e41f4b71Sopenharmony_ci    },
96e41f4b71Sopenharmony_ci    toggleShow: function() {
97e41f4b71Sopenharmony_ci        this.array.push ({"value": "Item" + this.i })
98e41f4b71Sopenharmony_ci        this.i++
99e41f4b71Sopenharmony_ci    },
100e41f4b71Sopenharmony_ci    toggleDisplay: function() {
101e41f4b71Sopenharmony_ci        this.display = !this.display
102e41f4b71Sopenharmony_ci    },
103e41f4b71Sopenharmony_ci}
104e41f4b71Sopenharmony_ci```
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci![en-us-attributes](figures/en-us-attributes.gif)
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci### Example 2
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci```html
111e41f4b71Sopenharmony_ci<!-- xxx.hml -->
112e41f4b71Sopenharmony_ci<div class="container">
113e41f4b71Sopenharmony_ci    <div>
114e41f4b71Sopenharmony_ci        <text class="text1" dir='rtl' >hello world</text>
115e41f4b71Sopenharmony_ci    </div>
116e41f4b71Sopenharmony_ci    <div>
117e41f4b71Sopenharmony_ci        <text class="text2" dir='ltr' >hello world</text>
118e41f4b71Sopenharmony_ci    </div>
119e41f4b71Sopenharmony_ci</div>
120e41f4b71Sopenharmony_ci```
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci```css
123e41f4b71Sopenharmony_ci/* xxx.css */
124e41f4b71Sopenharmony_ci.container {
125e41f4b71Sopenharmony_ci    display: flex;
126e41f4b71Sopenharmony_ci    flex-direction: column;
127e41f4b71Sopenharmony_ci    justify-content: center;
128e41f4b71Sopenharmony_ci    align-items: center;
129e41f4b71Sopenharmony_ci    width: 100%;
130e41f4b71Sopenharmony_ci    height: 100%;
131e41f4b71Sopenharmony_ci}
132e41f4b71Sopenharmony_ci.text1{
133e41f4b71Sopenharmony_ci    width: 90%;
134e41f4b71Sopenharmony_ci    height: 100px;
135e41f4b71Sopenharmony_ci    background-color: aqua;
136e41f4b71Sopenharmony_ci}
137e41f4b71Sopenharmony_ci.text2{
138e41f4b71Sopenharmony_ci    width: 90%;
139e41f4b71Sopenharmony_ci    height: 100px;
140e41f4b71Sopenharmony_ci    background-color: blue;
141e41f4b71Sopenharmony_ci}
142e41f4b71Sopenharmony_ci```
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci![en-us_image1](figures/en-us_image1.png)
145