SVG Radial gradient is defined by the
<radialGradient>
element which inserted with in the
<defs>
tags only which contains definitions of the special elements like gradient. In the radial gradient two offsets are defined with the two colors. Following are the attributes of the radial gradient.
- cx
x-axis coordinate of the circle gradient vector the default value is 0.
- cy
y-axis coordinate of the circle gradient vector the default value is 0.
- r
Radius of largest circle of gradient vector the default value is 0.
- fx
Radial gradient focal point the default value is o.
- fy
Radial gradient focal point the default value is o.
The code below demonstrates the radial gradient with the multiple colors.
[html]
<html>
<title>SVG Radial Gradient</title>
<body>
<h1>SVG Radial Gradient</h1>
<svg width="600" height="600">
<defs>
<radialGradient id="sampleGradient">
<stop offset="0%" stop-color="#FF0000" />
<stop offset="100%" stop-color="#00FFF00" />
</radialGradient>
</defs>
<g>
<text x="30" y="50" >Using Radial Gradient: </text>
<rect x="100" y="100" width="200" height="200" stroke="green" stroke-width="3"
fill="url(#sampleGradient)" />
</g>
</svg>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser then user will get the output as shown below.
The code below demonstrates the radial SVG Gradient with the multiple colors.
[html]
<!DOCTYPE html>
<html>
<h1>SPLessons</h1>
<body>
<svg height="150" width="500">
<defs>
<radialGradient id="grad1" cx="20%" cy="30%" r="30%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(0,255,255);stop-opacity:0" />
<stop offset="100%" style="stop-color:rgb(0,150,255);stop-opacity:1" />
</radialGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser then user will get the output as shown below.