

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw a linear gradient in HTML5?
This method returns a CanvasGradient object that represents a linear gradient that paints along the line given by the coordinates represented by the arguments. The four arguments represent the starting point (x1,y1) and end point (x2,y2) of the gradient.
createLinearGradient(x0, y0, x1, y1)
Here are the parameter values of the createLinearGradient() method −
S.No | Parameter & Description |
---|---|
1 | x0 x-coordinate- Starting point of the gradient |
2 | y0 y- coordinate - Starting point of the gradient |
3 | x1 x-coordinate - Ending point of the gradient |
4 | y1 y- coordinate - Ending point of the gradient |
Example
You can try to run the following code to learn how to draw a linear gradient in HTML5 −
<!DOCTYPE html> <html> <head> <title>HTML5 Linear Gradient</title> </head> <body> <canvas id="newCanvas" width="450" height="250" style="border:1px solid #d3d3d3;"></canvas> <script> var c = document.getElementById("newCanvas"); var ctxt = c.getContext("2d"); var linegrd = ctxt.createLinearGradient(0, 0, 170, 0); linegrd.addColorStop(0.5, "#E44D26"); linegrd.addColorStop(1, "#66CC00"); ctxt.fillStyle = linegrd; ctxt.fillRect(50, 80, 300, 100); </script> </body> </html>
- Related Questions & Answers
- How to draw a circular gradient in HTML5?
- CSS linear-gradient() Function
- Repeat a linear gradient with CSS
- How to apply linear gradient (color) to a node in JavaFX?
- Linear gradient with rainbow color
- How to draw a 3D sphere in HTML5?
- How to draw a circle in HTML5 SVG?
- How to draw a rectangle in HTML5 SVG?
- How to draw a line in HTML5 SVG?
- How to draw a polygon in HTML5 SVG?
- How to draw a polyline in HTML5 SVG?
- How to draw a star in HTML5 SVG?
- Linear gradient with multiple color stop
- Usage of linear-gradient() CSS function
- How to draw a rectangle on HTML5 Canvas?
Advertisements