1e41f4b71Sopenharmony_ci# text 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci> **NOTE** 5e41f4b71Sopenharmony_ci> 6e41f4b71Sopenharmony_ci> - This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> - The text content must be written in the content area. The **tspan** sub-element label can be nested to segment the text content. The **textPath** sub-element label can be nested to draw the text content based on the specified path. 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> - **\<text>** can be nested only by the parent element label **svg**. 11e41f4b71Sopenharmony_ci> 12e41f4b71Sopenharmony_ci> - Only the default font **sans-serif** is supported. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciThe **\<text>** component is used to display a piece of textual information. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## Required Permissions 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciNone 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## Child Components 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciThe following are supported: [\<tspan>](js-components-svg-tspan.md), [\<textpath>](js-components-svg-textpath.md), [\<animate>](js-components-svg-animate.md), and [\<animateTransform>](js-components-svg-animatetransform.md). 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci## Attributes 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciThe attributes in the following table are supported. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 31e41f4b71Sopenharmony_ci| -------------- | ---------------------------------- | ----- | ---- | ---------------------------------------- | 32e41f4b71Sopenharmony_ci| id | string | - | No | Unique ID of the component. | 33e41f4b71Sopenharmony_ci| x | <length> \| <percentage> | 0 | No | X-coordinate of the upper left corner of the component. | 34e41f4b71Sopenharmony_ci| y | <length> \| <percentage> | 0 | No | Y-coordinate of the upper left corner of the component. | 35e41f4b71Sopenharmony_ci| dx | <length> \| <percentage> | 0 | No | Offset of the text on the x-axis. | 36e41f4b71Sopenharmony_ci| dy | <length> \| <percentage> | 0 | No | Offset of the text on the y-axis. | 37e41f4b71Sopenharmony_ci| rotate | number | 0 | No | Rotation of the text around its lower left corner. A positive number indicates clockwise rotation, and a negative number indicates counterclockwise rotation. | 38e41f4b71Sopenharmony_ci| font-size | <length> | 30px | No | Font size. | 39e41f4b71Sopenharmony_ci| fill | <color> | black | No | Fill color of the text. | 40e41f4b71Sopenharmony_ci| fill-opacity | number | 1.0 | No | Fill opacity of the text. | 41e41f4b71Sopenharmony_ci| opacity | number | 1 | No | Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent. Attribute animations are supported.| 42e41f4b71Sopenharmony_ci| stroke | <color> | black | No | Stroke color. | 43e41f4b71Sopenharmony_ci| stroke-width | number | 1px | No | Stroke width. | 44e41f4b71Sopenharmony_ci| stroke-opacity | number | 1.0 | No | Stroke opacity. | 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci## Example 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci```css 50e41f4b71Sopenharmony_ci/* xxx.css */ 51e41f4b71Sopenharmony_ci.container { 52e41f4b71Sopenharmony_ci flex-direction: row; 53e41f4b71Sopenharmony_ci justify-content: flex-start; 54e41f4b71Sopenharmony_ci align-items: flex-start; 55e41f4b71Sopenharmony_ci height: 1000px; 56e41f4b71Sopenharmony_ci width: 1080px; 57e41f4b71Sopenharmony_ci} 58e41f4b71Sopenharmony_ci``` 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci```html 61e41f4b71Sopenharmony_ci<!-- xxx.hml --> 62e41f4b71Sopenharmony_ci<div class="container"> 63e41f4b71Sopenharmony_ci <svg> 64e41f4b71Sopenharmony_ci <text x="20px" y="0px" font-size="30" fill="blue">test x|y</text> 65e41f4b71Sopenharmony_ci <text x="150" y="15" font-size="30" fill="blue">test x|y</text> 66e41f4b71Sopenharmony_ci <text x="300" y="30" font-size="30" fill="blue" opacity="0.1">test opacity</text> 67e41f4b71Sopenharmony_ci <text dx="20" y="30" dy="50" fill="blue" font-size="30">test dx|dy|fill|font-size</text> 68e41f4b71Sopenharmony_ci <text x="20" y="150" fill="blue" font-size="30" fill-opacity="0.2">test fill-opacity</text> 69e41f4b71Sopenharmony_ci <text x="20" y="200" fill="red" font-size="40">test 0123456789</text> 70e41f4b71Sopenharmony_ci <text x="20" y="250" fill="red" font-size="40" fill-opacity="0.2">Test</text> 71e41f4b71Sopenharmony_ci <text x="20" y="300" rotate="30" fill="red" font-size="40">test rotate</text> 72e41f4b71Sopenharmony_ci <text x="20" y="350" fill="blue" font-size="40" stroke="red" stroke-width="2">test stroke</text> 73e41f4b71Sopenharmony_ci <text x="20" y="400" fill="white" font-size="40" stroke="red" stroke-width="2" stroke-opacity="0.5">test stroke-opacity</text> 74e41f4b71Sopenharmony_ci </svg> 75e41f4b71Sopenharmony_ci</div> 76e41f4b71Sopenharmony_ci``` 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciAttribute animation example 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci```css 83e41f4b71Sopenharmony_ci/* xxx.css */ 84e41f4b71Sopenharmony_ci.container { 85e41f4b71Sopenharmony_ci flex-direction: row; 86e41f4b71Sopenharmony_ci justify-content: flex-start; 87e41f4b71Sopenharmony_ci align-items: flex-start; 88e41f4b71Sopenharmony_ci height: 3000px; 89e41f4b71Sopenharmony_ci width: 1080px; 90e41f4b71Sopenharmony_ci} 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci```html 94e41f4b71Sopenharmony_ci<!-- xxx.hml --> 95e41f4b71Sopenharmony_ci<div class="container"> 96e41f4b71Sopenharmony_ci <svg> 97e41f4b71Sopenharmony_ci <text y="50" font-size="30" fill="blue"> 98e41f4b71Sopenharmony_ci text attribute x|opacity|rotate 99e41f4b71Sopenharmony_ci <animate attributeName="x" from="100" by="400" dur="3s" repeatCount="indefinite"></animate> 100e41f4b71Sopenharmony_ci <animate attributeName="opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate> 101e41f4b71Sopenharmony_ci <animate attributeName="rotate" from="0" to="360" dur="3s" repeatCount="indefinite"></animate> 102e41f4b71Sopenharmony_ci </text> 103e41f4b71Sopenharmony_ci </svg> 104e41f4b71Sopenharmony_ci</div> 105e41f4b71Sopenharmony_ci``` 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci```html 110e41f4b71Sopenharmony_ci<!-- xxx.hml --> 111e41f4b71Sopenharmony_ci<div class="container"> 112e41f4b71Sopenharmony_ci <svg> 113e41f4b71Sopenharmony_ci <text x="20" y="200" fill="blue"> 114e41f4b71Sopenharmony_ci text attribute font-size 115e41f4b71Sopenharmony_ci <animate attributeName="font-size" from="10" to="50" dur="3s" repeatCount="indefinite"> 116e41f4b71Sopenharmony_ci </animate> 117e41f4b71Sopenharmony_ci </text> 118e41f4b71Sopenharmony_ci </svg> 119e41f4b71Sopenharmony_ci</div> 120e41f4b71Sopenharmony_ci``` 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci```html 125e41f4b71Sopenharmony_ci<!-- xxx.hml --> 126e41f4b71Sopenharmony_ci<div class="container"> 127e41f4b71Sopenharmony_ci <svg> 128e41f4b71Sopenharmony_ci <text x="20" y="250" font-size="25" fill="blue" stroke="red"> 129e41f4b71Sopenharmony_ci text attribute stroke 130e41f4b71Sopenharmony_ci <animate attributeName="stroke" from="red" to="#00FF00" dur="3s" repeatCount="indefinite"></animate> 131e41f4b71Sopenharmony_ci </text> 132e41f4b71Sopenharmony_ci <text x="300" y="250" font-size="25" fill="white" stroke="red"> 133e41f4b71Sopenharmony_ci text attribute stroke-width-opacity 134e41f4b71Sopenharmony_ci <animate attributeName="stroke-width" from="1" to="5" dur="3s" repeatCount="indefinite"></animate> 135e41f4b71Sopenharmony_ci <animate attributeName="stroke-opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate> 136e41f4b71Sopenharmony_ci </text> 137e41f4b71Sopenharmony_ci </svg> 138e41f4b71Sopenharmony_ci</div> 139e41f4b71Sopenharmony_ci``` 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci 142