Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVG Gradient - Radial

SVG Gradient - Radial

In SVG, the The element is used to create a radial gradient, which spreads outward from a center point to form a gradient effect, giving graphics rich color variations such as rings and radial patterns.

Radial gradients can be applied to fill or stroke SVG graphic elements, adding a sense of depth and visual effects.

Basic Syntax



  

  

  



Parameter Description:

The following code defines a radial gradient from red to blue, then applies it to a filled circle, giving the circle a gradient fill effect.

Example

 

 

   

   

 

 

 

 

Example 1

Define a radial gradient from white to blue ellipse:

Below is the SVG code:

Example

 

   

     

     

   

 

 

Try it »

Click to view:View SVG File.

Code analysis:

  • The id attribute of the tag can define a unique name for the gradient
  • The CX, CY and r attributes define the outermost circle, and Fx and Fy define the innermost circle
  • The gradient color range can consist of two or more colors. Each color is specified with atag. The offset attribute is used to define the start and end of the gradient color
  • The fill attribute links the ellipse element to this gradient

Example 2

Define another ellipse with a radial gradient from white to blue:

Below is the SVG code:

Example

 

   

     

     

   

 

 

Try it »

Click to view:View SVG File.

Notes

  • A gradient can contain multiple elements, each element represents a color and position in the gradient.

  • cx, cy and r The attribute determines the center and radius of the gradient, while fx and fy The attribute is used to control the gradient focus, adjusting the shape and direction of the gradient.

  • Gradient coordinate values can use percentages or specific length values; percentage values are relative to the size of the graphic element.

  • Radial gradients can be applied to fill or stroke SVG graphic elements.

By using The element, you can create colorful radial gradient effects, adding depth and visual appeal to SVG graphic elements.