1e41f4b71Sopenharmony_ci# textPath
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<textPath>** component is used to draw text along the path.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci>  **NOTE**
7e41f4b71Sopenharmony_ci>  - This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>  - This component can have **\<tspan>** components nested for segmenting.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci>  - This component can only be nested in the **\<text>** component.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Required Permissions
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciNone
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## Child Components
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciThe **[\<tspan>](js-components-svg-tspan.md)** child component is supported.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Attributes
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ciThe attributes in the following table are supported.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name          | Type                              | Default Value| Description                                                        |
30e41f4b71Sopenharmony_ci| -------------- | ---------------------------------- | ------ | ------------------------------------------------------------ |
31e41f4b71Sopenharmony_ci| id             | string                             | -      | Unique ID of the component.                                            |
32e41f4b71Sopenharmony_ci| path           | string                             | 0      | Shape of the path.<br>The meanings of the letters are as follows:<br>- M = moveto<br>- L = lineto<br>- H = horizontal lineto<br>- V = vertical lineto<br>- C = curveto<br>- S = smooth curveto<br>- Q = quadratic Belzier curve<br>- T = smooth quadratic Belzier curveto<br>- A = elliptical Arc<br>- Z = closepath<br>Default value: **0**|
33e41f4b71Sopenharmony_ci| startOffset    | &lt;length&gt;\|&lt;percentage&gt; | 0      | Offset of the text start point relative to the path start point.<br>Default value: **0**                |
34e41f4b71Sopenharmony_ci| font-size      | &lt;length&gt;                     | 30px   | Font size.<br>Default value: **30px**                           |
35e41f4b71Sopenharmony_ci| fill           | &lt;color&gt;                      | black  | Font fill color.<br>Default value: **black**                            |
36e41f4b71Sopenharmony_ci| by             | number                             | -      | Attribute offset relative to the specified animation. By default, **from** is the original attribute value.            |
37e41f4b71Sopenharmony_ci| opacity        | number                             | 1      | 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.<br>Default value: **0**|
38e41f4b71Sopenharmony_ci| fill-opacity   | number                             | 1.0    | Font fill opacity.<br>Default value: **1.0**                            |
39e41f4b71Sopenharmony_ci| stroke         | &lt;color&gt;                      | black  | Stroke color.<br>Default value: **black**                  |
40e41f4b71Sopenharmony_ci| stroke-width   | number                             | 1px    | Stroke width.<br>Default value: **1px**                              |
41e41f4b71Sopenharmony_ci| stroke-opacity | number                             | 1.0    | Stroke opacity.<br>Default value: **1.0**                            |
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci## Example
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciThe following is an example of the **\<textspan>** attributes, where text is drawn along the path specified by **path**, and the start point is offset by 20% of the **path** length. (The drawn **\<path>** curve is for reference only.)
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci```html
49e41f4b71Sopenharmony_ci<!-- xxx.hml -->
50e41f4b71Sopenharmony_ci<div class="container">
51e41f4b71Sopenharmony_ci  <svg fill="#00FF00" x="50">
52e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none"></path>
53e41f4b71Sopenharmony_ci    <text>
54e41f4b71Sopenharmony_ci      <textpath fill="blue" startOffset="20%" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
55e41f4b71Sopenharmony_ci        This is textpath test.
56e41f4b71Sopenharmony_ci      </textpath>
57e41f4b71Sopenharmony_ci    </text>
58e41f4b71Sopenharmony_ci  </svg>
59e41f4b71Sopenharmony_ci</div>
60e41f4b71Sopenharmony_ci```
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci```css
63e41f4b71Sopenharmony_ci/* xxx.css */
64e41f4b71Sopenharmony_ci.container {
65e41f4b71Sopenharmony_ci    flex-direction: row;
66e41f4b71Sopenharmony_ci    justify-content: flex-start;
67e41f4b71Sopenharmony_ci    align-items: flex-start;
68e41f4b71Sopenharmony_ci    height: 1200px;
69e41f4b71Sopenharmony_ci    width: 600px;
70e41f4b71Sopenharmony_ci}
71e41f4b71Sopenharmony_ci```
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci![textpath-part1](figures/textpath-part1.png)
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciCombination of **\<textpath>** and **\<tspan>**
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci```html
79e41f4b71Sopenharmony_ci<!-- xxx.hml -->
80e41f4b71Sopenharmony_ci<div class="container">
81e41f4b71Sopenharmony_ci  <svg fill="#00FF00" x="50">
82e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none"></path>
83e41f4b71Sopenharmony_ci      <text>
84e41f4b71Sopenharmony_ci        <textpath fill="blue" startOffset="20%" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="15px">
85e41f4b71Sopenharmony_ci          <tspan dx="-50px" fill="red">This is tspan onTextPath.</tspan>
86e41f4b71Sopenharmony_ci          <tspan font-size="25px">Let's play.</tspan>
87e41f4b71Sopenharmony_ci          <tspan font-size="30px" fill="#00FF00">12345678912354567891234567891234567891234567891234567890</tspan>
88e41f4b71Sopenharmony_ci        </textpath>
89e41f4b71Sopenharmony_ci      </text>
90e41f4b71Sopenharmony_ci  </svg>
91e41f4b71Sopenharmony_ci</div>
92e41f4b71Sopenharmony_ci```
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci![textpath-part2](figures/textpath-part2.png)
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci```html
97e41f4b71Sopenharmony_ci<!-- xxx.hml -->
98e41f4b71Sopenharmony_ci<div class="container">
99e41f4b71Sopenharmony_ci  <svg fill="#00FF00" x="50">
100e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none"></path>
101e41f4b71Sopenharmony_ci    <text>
102e41f4b71Sopenharmony_ci      <textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px" stroke="black" stroke-width="1" >
103e41f4b71Sopenharmony_ci        This is TextPath.
104e41f4b71Sopenharmony_ci        <tspan font-size="20px" fill="red">This is tspan onTextPath.</tspan>
105e41f4b71Sopenharmony_ci        <tspan font-size="30px">Let's play.</tspan>
106e41f4b71Sopenharmony_ci        <tspan font-size="40px" fill="#00FF00"  stroke="blue" stroke-width="2">12345678912354567891234567891234567891234567891234567890
107e41f4b71Sopenharmony_ci        </tspan>
108e41f4b71Sopenharmony_ci      </textpath>
109e41f4b71Sopenharmony_ci    </text>
110e41f4b71Sopenharmony_ci  </svg>
111e41f4b71Sopenharmony_ci</div>
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci![textpath-part3](figures/textpath-part3.png)
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci```html
117e41f4b71Sopenharmony_ci<!-- xxx.hml -->
118e41f4b71Sopenharmony_ci<div class="container">
119e41f4b71Sopenharmony_ci  <svg fill="#00FF00" x="50">
120e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none">
121e41f4b71Sopenharmony_ci    </path>
122e41f4b71Sopenharmony_ci    <!--      Value percentage    -->
123e41f4b71Sopenharmony_ci    <text>
124e41f4b71Sopenharmony_ci      <textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
125e41f4b71Sopenharmony_ci        This is TextPath.
126e41f4b71Sopenharmony_ci        <tspan x="50" fill="blue">This is first tspan.</tspan>
127e41f4b71Sopenharmony_ci        <tspan x="50%">This is second tspan.</tspan>
128e41f4b71Sopenharmony_ci        <tspan dx="10%">12345678912354567891234567891234567891234567891234567890</tspan>
129e41f4b71Sopenharmony_ci      </textpath>
130e41f4b71Sopenharmony_ci    </text>
131e41f4b71Sopenharmony_ci  </svg>
132e41f4b71Sopenharmony_ci</div>
133e41f4b71Sopenharmony_ci```
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci![textpath-part4](figures/textpath-part4.png)
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ciThe following is an example of the **startOffset** animation, where the value of **startOffset** changes from 10% to 40%, and the text is not drawn when its length exceeds the path length range.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci```css
140e41f4b71Sopenharmony_ci/* xxx.css */
141e41f4b71Sopenharmony_ci.container {
142e41f4b71Sopenharmony_ci    flex-direction: row;
143e41f4b71Sopenharmony_ci    justify-content: flex-start;
144e41f4b71Sopenharmony_ci    align-items: flex-start;
145e41f4b71Sopenharmony_ci    height: 3000px;
146e41f4b71Sopenharmony_ci    width: 1080px;
147e41f4b71Sopenharmony_ci}
148e41f4b71Sopenharmony_ci```
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci```html
151e41f4b71Sopenharmony_ci<!-- xxx.hml -->
152e41f4b71Sopenharmony_ci<div class="container">
153e41f4b71Sopenharmony_ci  <svg fill="#00FF00">
154e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none"></path>
155e41f4b71Sopenharmony_ci    <text>
156e41f4b71Sopenharmony_ci      <textpath fill="blue" startOffset="10%" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="15px">
157e41f4b71Sopenharmony_ci        <tspan dx="-50px" fill="red">This is tspan onTextPath.</tspan>
158e41f4b71Sopenharmony_ci        <tspan font-size="25px">Let's play.</tspan>
159e41f4b71Sopenharmony_ci        <tspan font-size="30px" fill="#00FF00">12345678912354567891234567891234567891234567891234567890</tspan>
160e41f4b71Sopenharmony_ci        <animate attributeName="startOffset" from="10%" to="40%" dur="3s" repeatCount="indefinite"></animate>
161e41f4b71Sopenharmony_ci      </textpath>
162e41f4b71Sopenharmony_ci    </text>
163e41f4b71Sopenharmony_ci  </svg>
164e41f4b71Sopenharmony_ci</div>
165e41f4b71Sopenharmony_ci```
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci![textpath-animate1](figures/textpath-animate1.gif)
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ciAttribute animation of the **\<textPath>** and **\<tspan>** in combination
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci```html
172e41f4b71Sopenharmony_ci<!-- xxx.hml -->
173e41f4b71Sopenharmony_ci<div class="container">
174e41f4b71Sopenharmony_ci  <svg fill="#00FF00">
175e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none">
176e41f4b71Sopenharmony_ci    </path>
177e41f4b71Sopenharmony_ci    <text>
178e41f4b71Sopenharmony_ci      <textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
179e41f4b71Sopenharmony_ci        This is TextPath.
180e41f4b71Sopenharmony_ci        <tspan x="50" fill="blue">
181e41f4b71Sopenharmony_ci          tspan attribute x|rotate
182e41f4b71Sopenharmony_ci          <animate attributeName="x" from="50" to="100" dur="5s" repeatCount="indefinite"></animate>
183e41f4b71Sopenharmony_ci          <animate attributeName="rotate" from="0" to="360" dur="5s" repeatCount="indefinite"></animate>
184e41f4b71Sopenharmony_ci        </tspan>
185e41f4b71Sopenharmony_ci        <tspan x="30%">tspan static.</tspan>
186e41f4b71Sopenharmony_ci        <tspan>
187e41f4b71Sopenharmony_ci          tspan attribute dx|opacity
188e41f4b71Sopenharmony_ci          <animate attributeName="dx" from="0%" to="30%" dur="3s" repeatCount="indefinite"></animate>
189e41f4b71Sopenharmony_ci          <animate attributeName="opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
190e41f4b71Sopenharmony_ci        </tspan>
191e41f4b71Sopenharmony_ci        <tspan dx="5%">tspan move</tspan>
192e41f4b71Sopenharmony_ci      </textpath>
193e41f4b71Sopenharmony_ci    </text>
194e41f4b71Sopenharmony_ci  </svg>
195e41f4b71Sopenharmony_ci</div>
196e41f4b71Sopenharmony_ci```
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci![textpath-animate2](figures/textpath-animate2.gif)
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci(1) **"tspan attribute x|rotate"**: The beginning of the text is offset from 50 px to 100 px, and the text rotates clockwise by 0 degrees to 360 degrees.
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci(2) **"tspan attribute dx|opacity"**: The text is drawn after the "tspan static." drawing is complete. The horizontal offset moves from 0% to 30%, and the opacity changes from shallow to deep.
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci(3) **tspan move**: After the previous **\<tspan>** is drawn, the next **\<tspan>** is drawn with an offset of 5%, creating the effect of following the previous **\<tspan>**.
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ciAttribute animation of the **\<textPath>** and **\<tspan>** in combination
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci```html
209e41f4b71Sopenharmony_ci<!-- xxx.hml -->
210e41f4b71Sopenharmony_ci<div class="container">
211e41f4b71Sopenharmony_ci  <svg fill="#00FF00">
212e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" 
213e41f4b71Sopenharmony_ci      fill="none">
214e41f4b71Sopenharmony_ci    </path>
215e41f4b71Sopenharmony_ci    <text>
216e41f4b71Sopenharmony_ci      <textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
217e41f4b71Sopenharmony_ci        This is TextPath.
218e41f4b71Sopenharmony_ci        <tspan dx="20" fill="blue">
219e41f4b71Sopenharmony_ci          tspan attribute fill|fill-opacity
220e41f4b71Sopenharmony_ci          <animate attributeName="fill" from="blue" to="red" dur="3s" repeatCount="indefinite"></animate>
221e41f4b71Sopenharmony_ci          <animate attributeName="fill-opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
222e41f4b71Sopenharmony_ci        </tspan>
223e41f4b71Sopenharmony_ci        <tspan dx="20" fill="blue">
224e41f4b71Sopenharmony_ci          tspan attribute font-size
225e41f4b71Sopenharmony_ci          <animate attributeName="font-size" from="10" to="50" dur="3s" repeatCount="indefinite"></animate>
226e41f4b71Sopenharmony_ci        </tspan>
227e41f4b71Sopenharmony_ci      </textpath>
228e41f4b71Sopenharmony_ci        <tspan font-size="30">Single tspan</tspan>
229e41f4b71Sopenharmony_ci    </text>
230e41f4b71Sopenharmony_ci  </svg>
231e41f4b71Sopenharmony_ci</div>
232e41f4b71Sopenharmony_ci```
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci![textpath-animate3](figures/textpath-animate3.gif)
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci(1) **"This is TextPath."**: The first segment of text, in the size of 30px and color of \#D2691E is drawn on the path without offset.
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci(2) **"tspan attribute fill|fill-opacity"**: The new segment of text is 20px offset from the end of the previous text segment. The text color changes from blue to red, and the opacity changes from light to deep.
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci(3) **"tspan attribute font-size"**: The new segment of text is 20px offset from the end of the previous text segment. While the start point of the text is static, the font size shifts from 10px to 50px and the overall length is continuously prolonged.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci(4) **"Single tspan"**: A horizontal line is drawn at the end of the previous segment, creating the effect of following the previous segment.
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ciAttribute animation of the **\<textPath>** and **\<tspan>** in combination
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci```html
247e41f4b71Sopenharmony_ci<!-- xxx.hml -->
248e41f4b71Sopenharmony_ci<div class="container">
249e41f4b71Sopenharmony_ci  <svg fill="#00FF00">
250e41f4b71Sopenharmony_ci    <path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" 
251e41f4b71Sopenharmony_ci      fill="none">
252e41f4b71Sopenharmony_ci    </path>
253e41f4b71Sopenharmony_ci    <text>
254e41f4b71Sopenharmony_ci      <textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
255e41f4b71Sopenharmony_ci          This is TextPath.
256e41f4b71Sopenharmony_ci          <tspan dx="20" fill="blue">
257e41f4b71Sopenharmony_ci            tspan attribute stroke
258e41f4b71Sopenharmony_ci            <animate attributeName="stroke" from="red" to="#00FF00" dur="3s" repeatCount="indefinite"></animate>
259e41f4b71Sopenharmony_ci          </tspan>
260e41f4b71Sopenharmony_ci          <tspan dx="20" fill="white" stroke="red">
261e41f4b71Sopenharmony_ci            tspan attribute stroke-width-opacity
262e41f4b71Sopenharmony_ci            <animate attributeName="stroke-width" from="1" to="5" dur="3s" repeatCount="indefinite"></animate>
263e41f4b71Sopenharmony_ci            <animate attributeName="stroke-opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
264e41f4b71Sopenharmony_ci          </tspan>
265e41f4b71Sopenharmony_ci      </textpath>
266e41f4b71Sopenharmony_ci    </text>
267e41f4b71Sopenharmony_ci  </svg>
268e41f4b71Sopenharmony_ci</div>
269e41f4b71Sopenharmony_ci```
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci![textpath-animate4](figures/textpath-animate4.gif)
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci(1) **"tspan attribute stroke"**: The stroke color gradually changes from red to green.
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci(2) **"tspan attribute stroke-width-opacity"**: The stroke width changes from 1px to 5px, and the opacity changes from shallow to deep.
276