1e41f4b71Sopenharmony_ci# Basics
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **<svg>** component is used as the root node of the SVG canvas and can be nested in the SVG. For details, see [svg](../reference/apis-arkui/arkui-js/js-components-svg.md).
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **NOTE**
8e41f4b71Sopenharmony_ci> 
9e41f4b71Sopenharmony_ci> The width and height must be defined for the **<svg>** parent component or **<svg>** component. Otherwise, the component is not drawn.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## Creating an <svg> Component
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciCreate a **<svg>** component in the .hml file under **pages/index**.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```html
18e41f4b71Sopenharmony_ci<!-- xxx.hml -->
19e41f4b71Sopenharmony_ci<div class="container">
20e41f4b71Sopenharmony_ci  <svg width="400" height="400">  </svg>
21e41f4b71Sopenharmony_ci</div>
22e41f4b71Sopenharmony_ci```
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci```css
26e41f4b71Sopenharmony_ci/* xxx.css */
27e41f4b71Sopenharmony_ci.container{
28e41f4b71Sopenharmony_ci  width: 100%;
29e41f4b71Sopenharmony_ci  height: 100%;
30e41f4b71Sopenharmony_ci  flex-direction: column;
31e41f4b71Sopenharmony_ci  align-items: center;
32e41f4b71Sopenharmony_ci  justify-content: center;
33e41f4b71Sopenharmony_ci  background-color: #F1F3F5;
34e41f4b71Sopenharmony_ci}
35e41f4b71Sopenharmony_cisvg{
36e41f4b71Sopenharmony_ci  background-color: blue;
37e41f4b71Sopenharmony_ci}
38e41f4b71Sopenharmony_ci```
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci![en-us_image_0000001232162324](figures/en-us_image_0000001232162324.png)
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## Setting Attributes
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciSet the **width**, **height**, **x**, **y**, and **viewBox** attributes to define the width, height, X coordinate, Y coordinate, and SVG viewport of the **&lt;svg&gt;** component.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci```html
49e41f4b71Sopenharmony_ci<!-- xxx.hml -->
50e41f4b71Sopenharmony_ci<div class="container">
51e41f4b71Sopenharmony_ci  <svg width="400" height="400" viewBox="0 0 100 100">    
52e41f4b71Sopenharmony_ci    <svg class="rect" width="100" height="100" x="20" y="10">    
53e41f4b71Sopenharmony_ci    </svg>  
54e41f4b71Sopenharmony_ci  </svg>
55e41f4b71Sopenharmony_ci</div>
56e41f4b71Sopenharmony_ci```
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci```css
60e41f4b71Sopenharmony_ci/* xxx.css */
61e41f4b71Sopenharmony_ci.container{
62e41f4b71Sopenharmony_ci  width: 100%;
63e41f4b71Sopenharmony_ci  height: 100%;
64e41f4b71Sopenharmony_ci  flex-direction: column;
65e41f4b71Sopenharmony_ci  align-items: center;
66e41f4b71Sopenharmony_ci  justify-content: center;
67e41f4b71Sopenharmony_ci  background-color: #F1F3F5;
68e41f4b71Sopenharmony_ci}
69e41f4b71Sopenharmony_cisvg{
70e41f4b71Sopenharmony_ci  background-color: yellow;
71e41f4b71Sopenharmony_ci}
72e41f4b71Sopenharmony_ci.rect{
73e41f4b71Sopenharmony_ci  background-color: red;
74e41f4b71Sopenharmony_ci}
75e41f4b71Sopenharmony_ci```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci![en-us_image_0000001231683152](figures/en-us_image_0000001231683152.png)
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci> **NOTE**
80e41f4b71Sopenharmony_ci>
81e41f4b71Sopenharmony_ci> - If the **&lt;svg&gt;** component is the root node, the X-axis and Y-axis attributes are invalid.
82e41f4b71Sopenharmony_ci>
83e41f4b71Sopenharmony_ci> - If the width and height of **viewBox** are inconsistent with those of the **&lt;svg&gt;** component, the view box will be scaled in center-aligned mode.
84