1# Universal Text Attributes
2
3Universal text attributes include text style attributes applicable to text containers.
4
5>  **NOTE**
6>
7>  The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9## fontColor
10
11fontColor(value: ResourceColor)
12
13Sets the font color.
14
15**Widget capability**: This API can be used in ArkTS widgets since API version 9.
16
17**Atomic service API**: This API can be used in atomic services since API version 11.
18
19**System capability**: SystemCapability.ArkUI.ArkUI.Full
20
21**Parameters**
22
23| Name| Type                                      | Mandatory| Description      |
24| ------ | ------------------------------------------ | ---- | ---------- |
25| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Font color.|
26
27## fontSize
28
29fontSize(value: number | string | Resource)
30
31Sets the font size.
32
33**Widget capability**: This API can be used in ArkTS widgets since API version 9.
34
35**Atomic service API**: This API can be used in atomic services since API version 11.
36
37**System capability**: SystemCapability.ArkUI.ArkUI.Full
38
39**Parameters**
40
41| Name| Type                                                        | Mandatory| Description                                                        |
42| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
43| value  | [Resource](ts-types.md#resource) \| number \| string | Yes  | Font size. If **fontSize** is of the number type, the unit fp is used. The default font size is 16 fp. This parameter cannot be set in percentage.|
44
45## fontStyle
46
47fontStyle(value: FontStyle)
48
49Sets the font style.
50
51**Widget capability**: This API can be used in ArkTS widgets since API version 9.
52
53**Atomic service API**: This API can be used in atomic services since API version 11.
54
55**System capability**: SystemCapability.ArkUI.ArkUI.Full
56
57**Parameters**
58
59| Name| Type                                       | Mandatory| Description                                   |
60| ------ | ------------------------------------------- | ---- | --------------------------------------- |
61| value  | [FontStyle](ts-appendix-enums.md#fontstyle) | Yes  | Font style.<br>Default value: **FontStyle.Normal**|
62
63## fontWeight
64
65fontWeight(value: number | FontWeight | string)
66
67Sets the font weight. If the value is too large, the text may be clipped depending on the font.
68
69**Widget capability**: This API can be used in ArkTS widgets since API version 9.
70
71**Atomic service API**: This API can be used in atomic services since API version 11.
72
73**System capability**: SystemCapability.ArkUI.ArkUI.Full
74
75**Parameters**
76
77| Name| Type                                                        | Mandatory| Description                                                        |
78| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
79| value  | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | Yes  | Font weight. For the number type, the value range is [100, 900], at an interval of 100. The default value is **400**. A larger value indicates a heavier font weight. For the string type, only strings that represent a number, for example, **"400"**, and the following enumerated values of **FontWeight** are supported: **"bold"**, **"bolder"**, **"lighter"**, **"regular"**, and **"medium"**.<br>Default value: **FontWeight.Normal**|
80
81## fontFamily
82
83fontFamily(value: string | Resource)
84
85Sets the font family.
86
87**Widget capability**: This API can be used in ArkTS widgets since API version 9.
88
89**Atomic service API**: This API can be used in atomic services since API version 11.
90
91**System capability**: SystemCapability.ArkUI.ArkUI.Full
92
93**Parameters**
94
95| Name| Type                                                | Mandatory| Description                                                        |
96| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
97| value  | [Resource](ts-types.md#resource) \| string | Yes  | Font family. Default font: **'HarmonyOS Sans'**<br>The 'HarmonyOS Sans' font and [registered custom fonts](../js-apis-font.md) are supported for applications.<br>Only the 'HarmonyOS Sans' font is supported for widgets.|
98
99## lineHeight
100
101lineHeight(value: number | string | Resource)
102
103Sets the text line height. If the value is less than or equal to **0**, the line height is not limited and the font size is adaptive.
104
105**Widget capability**: This API can be used in ArkTS widgets since API version 9.
106
107**Atomic service API**: This API can be used in atomic services since API version 11.
108
109**System capability**: SystemCapability.ArkUI.ArkUI.Full
110
111**Parameters**
112
113| Name| Type                                                        | Mandatory| Description                              |
114| ------ | ------------------------------------------------------------ | ---- | ---------------------------------- |
115| value  | [Resource](ts-types.md#resource) \| number \| string | Yes  | Text line height. For number values, the unit is fp.|
116
117## decoration
118
119decoration(value: DecorationStyleInterface)
120
121Sets the style and color for the text decorative line.
122
123**Widget capability**: This API can be used in ArkTS widgets since API version 9.
124
125**Atomic service API**: This API can be used in atomic services since API version 11.
126
127**System capability**: SystemCapability.ArkUI.ArkUI.Full
128
129**Parameters**
130
131| Name| Type                                                        | Mandatory| Description                                                        |
132| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
133| value  | [DecorationStyleInterface<sup>12+</sup>](ts-universal-styled-string.md#decorationstyleinterface) | Yes  | Style of the text decorative line.<br>Default value:<br>{<br> type: TextDecorationType.None,<br> color: Color.Black,<br> style: TextDecorationStyle.SOLID <br>}<br>**NOTE**<br>The **style** parameter cannot be used in widgets.|
134
135## Example
136
137```ts
138// xxx.ets
139@Entry
140@Component
141struct TextStyleExample {
142  build() {
143    Column({ space: 5 }) {
144      Text('default text')
145
146      Text('text font color red').fontColor(Color.Red)
147
148      Text('text font default')
149      Text('text font size 10').fontSize(10)
150      Text('text font size 10fp').fontSize('10fp')
151      Text('text font size 20').fontSize(20)
152
153      Text('text font style Italic').fontStyle(FontStyle.Italic)
154
155      Text('text fontWeight bold').fontWeight(700)
156      Text('text fontWeight lighter').fontWeight(FontWeight.Lighter)
157
158      Text('red 20 Italic bold text')
159        .fontColor(Color.Red)
160        .fontSize(20)
161        .fontStyle(FontStyle.Italic)
162        .fontWeight(FontWeight.Bold)
163
164      Text('Orange 18 Normal text')
165        .fontColor(Color.Orange)
166        .fontSize(18)
167        .fontStyle(FontStyle.Normal)
168    }.width('100%')
169  }
170}
171```
172
173![textstyle](figures/textstyle.png)
174