# RichText The **RichText** component parses and displays HTML text. - Applicable scenarios: The **RichText** component is suitable for loading and displaying segments of HTML strings in scenarios where extensive customization of the display effect is not required. The component supports only a limited set of universal attributes and events. For details, see [Attributes](#attributes) and [Events](#events). The underlying layer of the **RichText** component uses the **Web** component to provide basic capabilities, including but not limited to HTML page parsing and rendering. Therefore, the use of the **RichText** component needs to follow **Web** component constraints. Common typical constraints are as follows: The default viewport size of a mobile device is 980 px, which can ensure that most web pages can be viewed correctly on mobile devices. If the width of the **RichText** component is lower than this value, the HTML inside the content may generate a scrollable page wrapped by the **RichText** component. If you want to replace the default value, add the following tags to **content**: ```html ``` - Inapplicable scenarios: The **RichText** component is not suitable for scenarios where there is a need for extensive customization of the display effect of the HTML string. For example, the **RichText** component does not allow for changing the background color, font color, font size, or content by setting attributes and events. Under such scenarios, the [Web](../../apis-arkweb/ts-basic-components-web.md) component is recommended. The **RichText** component can be memory-intensive. If it is reused in scenarios such as lists where multiple instances are created, slow scrolling or rendering may result. Under such scenarios, you may want to use the [RichEditor](../arkui-ts/ts-basic-components-richeditor.md#richeditor) component. > **NOTE** > > - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > - This component is not able to auto-adapt its width and height to the content. Therefore, you must set the layout when using this component. ## Child Components Not supported ## APIs RichText(content:string) **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name| Type| Mandatory | Description| | ------- | -------- | ------------- | -------- | | content | string | Yes | String in HTML format.| ## Events ### onStart onStart(callback: () => void) Triggered when web page loading starts. **System capability**: SystemCapability.ArkUI.ArkUI.Full ### onComplete onComplete(callback: () => void) Triggered when web page loading is completed. **System capability**: SystemCapability.ArkUI.ArkUI.Full ## Attributes Among the [universal attributes](ts-universal-attributes-size.md), only the **width**, **height**, **size**, and **layoutWeight** attributes are supported. ## Supported Tags | Name| Description| Example| | -------- | -------- | -------- | | \
\
| Defines a paragraph.| \This is a paragraph\
| | \This is a paragraph\
This is a new paragraph\
| \This is in red\ | | \
This is text\
\This is text\
| | \\This is an underlined paragraph\\
| | \ | Used to embed CSS within an HTML document.| \ | | style | Defines the inline style of an element and is placed inside the tag. Use quotation marks (') to separate the styling text and use semicolons (;) to separate styles, for example, **style='width: 500px;height: 500px;border: 1px solid;margin: 0 auto;'**.| \This is text\
| | \ | Embeds or references a client-side script, such as JavaScript.| \ | ## Example You can preview how this component looks on a real device, but not in DevEco Studio Previewer. ```ts // xxx.ets @Entry @Component struct RichTextExample { @State data: string = 'Regular paragraph
Font size: 35px; line height: 45px
' + '' + '
This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.
'; build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { RichText(this.data) .onStart(() => { console.info('RichText onStart'); }) .onComplete(() => { console.info('RichText onComplete'); }) .width(500) .height(500) .backgroundColor(0XBDDB69) RichText('layoutWeight(1)') .onStart(() => { console.info('RichText onStart'); }) .onComplete(() => { console.info('RichText onComplete'); }) .size({ width: '100%', height: 110 }) .backgroundColor(0X92D6CC) .layoutWeight(1) RichText('layoutWeight(2)') .onStart(() => { console.info('RichText onStart'); }) .onComplete(() => { console.info('RichText onComplete'); }) .size({ width: '100%', height: 110 }) .backgroundColor(0X92C48D) .layoutWeight(2) } } } ``` 