HTML canvas createPattern() method
The image used:

Example
Repeat the image in both horizontal and vertical directions:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=document.getElementById("lamp");
var pat=ctx.createPattern(img,"repeat");
ctx.rect(0,0,150,100);
ctx.fillStyle=pat;
ctx.fill();
Try it »
Browser support





Internet Explorer 9, Firefox, Opera, Chrome and Safari support the createPattern() method.
**Note:** Internet Explorer 8 and earlier versions do not support
Definition and Usage
The createPattern() method repeats the specified element in the specified direction.
The element can be an image, a video, or other
The repeated element can be used to draw/fill rectangles, circles, or lines, and so on.
| JavaScript syntax: | context.createPattern(image,"repeat|repeat-x|repeat-y|no-repeat"); |
|---|
Parameter value
| Parameters | Description |
|---|---|
| image | Specifies the image, canvas, or video element to use for the pattern. |
| repeat | Default. The pattern repeats in both horizontal and vertical directions. |
| repeat-x | The pattern repeats only in the horizontal direction. |
| repeat-y | The pattern repeats only in the vertical direction. |
| no-repeat | The pattern is shown only once (not repeated). |
HTML canvas Reference Manual