SVG Linear Gradients

How to Linear Gradient?

The <linearGradient> SVG element define linear gradients that can be applied to fill or stroke of graphical elements.

In this example, we will apply the linear gradient starts from the left by using <linearGradient> SVG element.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg height="150" width="400"> <defs> <linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" style="stop-color:black;stop-opacity:1" /> <stop offset="100%" style="stop-color:gold;stop-opacity:1" /> </linearGradient> </defs> <circle cx="50" cy="50" r="40" fill="url(#grad)" /> </svg> </body> </html>

Linear Gradient from Top

In this example, we will apply the linear gradient starts from the top by using <linearGradient> SVG element.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg height="100" width="100"> <defs> <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:black;stop-opacity:1" /> <stop offset="100%" style="stop-color:gold;stop-opacity:1" /> </linearGradient> </defs> <circle cx="50" cy="50" r="40" fill="url(#grad1)" /> </svg> </body> </html>

Linear Gradient from Right

In this example, we will apply the linear gradient starts from the right by using <linearGradient> SVG element.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg height="100" width="100"> <defs> <linearGradient id="grad2" x1="100%" y1="0%" x2="0%" y2="0%"> <stop offset="0%" style="stop-color:black;stop-opacity:1" /> <stop offset="100%" style="stop-color:gold;stop-opacity:1" /> </linearGradient> </defs> <circle cx="50" cy="50" r="40" fill="url(#grad2)" /> </svg> </body> </html>

Linear Gradient from Bottom

In this example, we will apply the linear gradient starts from the bottom by using <linearGradient> SVG element.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg height="100" width="100"> <defs> <linearGradient id="grad3" x1="0%" y1="100%" x2="0%" y2="0%"> <stop offset="0%" style="stop-color:black;stop-opacity:1" /> <stop offset="100%" style="stop-color:gold;stop-opacity:1" /> </linearGradient> </defs> <circle cx="50" cy="50" r="40" fill="url(#grad3)" /> </svg> </body> </html>

Linear Gradient with Text

SUN

In this example, we will have a text above the circle with linear gradient.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg height="100" width="100"> <defs> <linearGradient id="grad4" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" style="stop-color:black;stop-opacity:1" /> <stop offset="100%" style="stop-color:gold;stop-opacity:1" /> </linearGradient> </defs> <circle cx="50" cy="50" r="40" fill="url(#grad4)" /> <text fill="#f7f7f7" font-size="25" font-family="Verdana" x="24" y="59">SUN</text> </svg> </body> </html>

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author