
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How do I make a transparent canvas in HTML5?
The globalAlpha property returns the transparency value of drawing. The value 1.0 of this property specifies no transparency and the value 0.0 of this property specifies full transparency. Hence, by setting the globalAlpha property to 0.0, we can get a transparent canvas.
Example
You can try to run the following code to make a transparent canvas −
<!DOCTYPE html> <html> <body> <canvas id = "idCanvas" width = "400" height = "200" style = "border:2px solid #000000;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("idCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "green"; ctx.fillRect(20, 20, 75, 50); ctx.globalAlpha = 0.0; ctx.fillStyle = "yellow"; ctx.fillRect(50, 50, 75, 50); ctx.fillStyle = "red"; ctx.fillRect(80, 80, 75, 50); </script> </body> </html>
- Related Articles
- How to make a Tkinter canvas rectangle transparent?
- How do I add a simple onClick event handler to an HTML5 canvas element?
- Make HTML5 Canvas fill the whole page
- How can I use the HTML5 canvas element in IE?
- How do I create a transparent Activity in an Android App?
- How do I update images on a Tkinter Canvas?
- How to center canvas in HTML5?
- HTML5 canvas ctx.fillText won't do line breaks
- How to make axes transparent in Matplotlib?
- Print a HTML5 canvas element
- How to detect point on canvas after canvas rotation in HTML5
- How to draw a rectangle on HTML5 Canvas?
- Translating HTML5 canvas
- HTML5 Canvas distorted
- HTML5 Canvas Transformation

Advertisements