YouTip LogoYouTip

Met Canvas Createpattern

# HTML canvas createPattern() Method [![Image 9: Canvas Object Reference](#) Canvas Object](#) ## Image Used: ![Image 10: Lamp](#) ## Example Repeat an image in horizontal and vertical directions: YourbrowserdoesnotsupporttheHTML5canvastag. 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 Yourself Β»](#) * * * ## Browser Support ![Image 11: Internet Explorer](#)![Image 12: Firefox](#)![Image 13: Opera](#)![Image 14: Google Chrome](#)![Image 15: Safari](#) The createPattern() method is supported in Internet Explorer 9, Firefox, Opera, Chrome, and Safari. **Note:** Internet Explorer 8 and earlier versions do not support the element. * * * ## Definition and Usage The createPattern() method repeats the specified element in the specified direction. The element can be an image, a video, or another element. The repeated element can be used to draw/fill rectangles, circles, lines, etc. | JavaScript syntax: | _context_.createPattern(_image_,"repeat|repeat-x|repeat-y|no-repeat"); | | --- | ## Parameter Values | Parameter | Description | | --- | --- | | _image_ | Specifies the image, canvas, or video element to use as the pattern. | | | repeat | Default. The pattern is repeated horizontally and vertically. | | repeat-x | The pattern is repeated only horizontally. | | repeat-y | The pattern is repeated only vertically. | | no-repeat | The pattern is displayed only once (not repeated). | * * Canvas Object](#)
← Met Canvas CreateradialgradienMet Canvas Createlineargradien β†’