1# canvas 2 3The **\<canvas>** component is used for customizing drawings. 4 5> **NOTE** 6> 7> This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version. 8 9 10## Child Components 11 12Not supported 13 14 15## Attributes 16 17| Name| Type| Default Value| Mandatory| Description| 18| -------- | -------- | -------- | -------- | -------- | 19| id | string | - | No| Unique ID of the component.| 20| style | string | - | No| Style declaration of the component.| 21| class | string | - | No| Style class of the component, which is used to refer to a style table.| 22| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.| 23 24 25## Events 26 27| Name| Parameter| Description| 28| -------- | -------- | -------- | 29| click | - | Triggered when the component is clicked.| 30| longpress | - | Triggered when the component is long pressed.| 31| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component.| 32 33 34## Styles 35 36| Name| Type| Default Value| Mandatory| Description| 37| -------- | -------- | -------- | -------- | -------- | 38| width | <length> \| <percentage><sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used. | 39| height | <length> \| <percentage><sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | 40| 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).| 41| 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).| 42| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.| 43| border-width | <length> | 0 | No| Shorthand attribute to set the margin for all sides.| 44| border-color | <color> | black | No| Shorthand attribute to set the color for all borders.| 45| border-radius | <length> | - | No| Radius of round-corner borders.| 46| background-color | <color> | - | No| Background color.| 47| 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| 48| [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. | 49 50 51## Methods 52 53| Name| Parameter| Description| 54| -------- | -------- | -------- | 55| 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