1# label
2
3>  **NOTE**
4>
5>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6
7The **\<label>** component defines labels for the **\<input>**, **\<button>**, and **\<textarea>** components. When a label is clicked, the click effect of the component associated with the label will be triggered.
8
9## Required Permissions
10
11None
12
13
14## Child Components
15
16Not supported
17
18
19## Attributes
20
21In addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported.
22
23| Name    | Type    | Default Value | Mandatory  | Description         |
24| ------ | ------ | ---- | ---- | ----------- |
25| target | string | -    | No   | Attribute ID of the target component.|
26
27
28## Styles
29
30In addition to the [universal styles](js-components-common-styles.md), the following styles are supported.
31
32| Name               | Type                        | Default Value       | Mandatory  | Description                                      |
33| ----------------- | -------------------------- | ---------- | ---- | ---------------------------------------- |
34| color             | &lt;color&gt;              | #e5000000  | No   | Font color.                                |
35| font-size         | &lt;length&gt;             | 30px       | No   | Font size.                                |
36| allow-scale       | boolean                    | true       | No   | Whether the font size changes with the system's font size settings.<br>For details about how to make the configuration take effect dynamically, see the **config-changes** attribute in the **config.json** file.|
37| letter-spacing    | &lt;length&gt;             | 0px        | No   | Character spacing (px).                              |
38| font-style        | string                     | normal     | No   | Font style. Available values are as follows:<br>- **normal**: standard font style.<br>- **italic**: italic font style.|
39| font-weight       | number \| string | normal     | No   | Font weight. For the number type, the value ranges from 100 to 900. The default value is 400. A larger value indicates a heavier font weight.<br>The value of the number type must be an integer multiple of 100.<br>The value of the string type can be **lighter**, **normal**, **bold**, or **bolder**.|
40| text-decoration   | string                     | none       | No   | Text decoration. Available values are as follows:<br>- **underline**: An underline is used.<br>- **line-through**: A strikethrough is used.<br>- **none**: The standard text is used.|
41| text-align        | string                     | start<br>| No   | Text alignment mode. Available values are as follows:<br>- **left**: The text is left-aligned.<br>- **center**: The text is center-aligned.<br>- **right**: The text is right-aligned.<br>- **start**: The text is aligned with the direction in which the text is written.<br>- **end**: The text is aligned with the opposite direction in which the text is written.<br>If the text width is not specified, the alignment effect may not be obvious when the text width is the same as the width of the parent container.|
42| line-height       | &lt;length&gt;             | 0px        | No   | Text line height. When this parameter is set to **0px**, the text line height is not limited and the font size is adaptive.      |
43| text-overflow     | string                     | clip       | No   | Takes effect when the maximum number of lines is specified. Available values are as follows:<br>- **clip**: The text is clipped and displayed based on the size of the parent container.<br>- **ellipsis**: The text is displayed based on the size of the parent container. The text that cannot be displayed is replaced with ellipsis. This style must be used together with **max-lines**.|
44| font-family       | string                     | sans-serif | No   | Font family, in which fonts are separated by commas (,). Each font is set using a font name or font family name. The first font in the family or the specified [custom font](js-components-common-customizing-font.md) is used for the text.|
45| max-lines         | number                     | -          | No   | Maximum number of lines in the text.                              |
46| min-font-size     | &lt;length&gt;             | -          | No   | Minimum font size in the text. This style must be used together with **max-font-size**. The font size can be changed dynamically. After the maximum and minimum font sizes are set, **font-size** does not take effect.|
47| max-font-size     | &lt;length&gt;             | -          | No   | Maximum font size in the text. This style must be used together with **min-font-size**. The font size can be changed dynamically. After the maximum and minimum font sizes are set, **font-size** does not take effect.|
48| font-size-step    | &lt;length&gt;             | 1px        | No   | Step for dynamically adjusting the font size in the text. The minimum and maximum font sizes must be set.           |
49| prefer-font-sizes | &lt;array&gt;              | -          | No   | Preset preferred font sizes. For dynamic font size adjustment, the preset sizes are used to match the maximum number of lines in the text. If the preferred font sizes were not set, the font size will be adjusted based on the maximum and minimum font sizes and the step you have set. If the maximum number of lines in the text cannot be met, **text-overflow** is used to truncate the text. If this parameter is set, **font-size**, **max-font-size**, **min-font-size**, and **font-size-step** do not take effect.<br>Example: prefer-font-sizes: 12px,14px,16px|
50
51
52## Events
53
54Not supported
55
56
57## Methods
58
59Not supported
60
61
62## Example
63
64```html
65<!--xxx.hml -->
66<div class="container">
67  <div class="row">
68    <label class="label" target="textId">input</label>
69    <input class="input" id="textId" type="text"></input>
70  </div>
71  <div class="row">
72    <label class="label" target="radioId">radio</label>
73    <input class="input" id="radioId" type="radio" name="group" value="group"></input>
74  </div>
75  <div class="row">
76    <label class="label" target="checkboxId">checkbox</label>
77    <input class="input" id="checkboxId" type="checkbox"></input>
78  </div>
79</div>
80```
81
82```css
83/*xxx.css */
84.container {
85  flex-direction: column;
86  margin-left: 20px;
87}
88.row {
89  flex-direction: row;
90}
91.label {
92  width: 200px;
93  margin-top: 50px;
94}
95.input {
96  margin-left: 100px;
97  margin-top: 50px;
98}
99```
100
101![en-us_image_0000001152834002](figures/en-us_image_0000001152834002.png)
102