1e41f4b71Sopenharmony_ci# canvas 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<canvas>** component is used for customizing drawings. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNot supported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 19e41f4b71Sopenharmony_ci| id | string | - | No| Unique ID of the component.| 20e41f4b71Sopenharmony_ci| style | string | - | No| Style declaration of the component.| 21e41f4b71Sopenharmony_ci| class | string | - | No| Style class of the component, which is used to refer to a style table.| 22e41f4b71Sopenharmony_ci| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.| 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## Events 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Parameter| Description| 28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 29e41f4b71Sopenharmony_ci| click | - | Triggered when the component is clicked.| 30e41f4b71Sopenharmony_ci| longpress | - | Triggered when the component is long pressed.| 31e41f4b71Sopenharmony_ci| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component.| 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## Styles 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 38e41f4b71Sopenharmony_ci| width | <length> \| <percentage><sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used. | 39e41f4b71Sopenharmony_ci| height | <length> \| <percentage><sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | 40e41f4b71Sopenharmony_ci| padding | <length> | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| 41e41f4b71Sopenharmony_ci| margin | <length> \| <percentage><sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| 42e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.| 43e41f4b71Sopenharmony_ci| border-width | <length> | 0 | No| Shorthand attribute to set the margin for all sides.| 44e41f4b71Sopenharmony_ci| border-color | <color> | black | No| Shorthand attribute to set the color for all borders.| 45e41f4b71Sopenharmony_ci| border-radius | <length> | - | No| Radius of round-corner borders.| 46e41f4b71Sopenharmony_ci| background-color | <color> | - | No| Background color.| 47e41f4b71Sopenharmony_ci| display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| 48e41f4b71Sopenharmony_ci| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## Methods 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| Name| Parameter| Description| 54e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 55e41f4b71Sopenharmony_ci| getContext | string | Obtains the context of the drawing on a canvas. The parameter can be set only to **2d**. The return value is a 2D drawing object that provides specific 2D drawing operations. For details, see [CanvasRenderingContext2D](js-lite-components-canvas-canvasrenderingcontext2d.md).| 56