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