# Gradients and Patterns

In addition to plain colors, the SVGs can use gradients and patterns to fill shapes. This allows for great freedom when building graphic designs. Usually, these elements are created within the defs, although it is unnecessary to place them there.

We can use them for .fill() and .stroke() values with the gradient's and pattern's method .url(). This method return the element's unique id reference with the pseudo-function url().

# Gradients

# Linear Gradients

linearGradient changes color uniformly along a straight line based on each of the color points (stop) and the transition between them. By default, the gradient is from left to right; if you need another angle (for example, 45), you can use .gradientTransform(rotate(45)).

The stop element is defined with an .offset() than receive a percentage, and .stop_color () and .stop_opacity() for define the color reference for that point.

# Radial Gradients

radialGradient is very similar to linearGradient, but in this case, the coordinates for the gradient are different, now is circular, from the center to the edge.

# Patterns

pattern defines a graphics object which can be redrawn on intervals into the SVG. It has its own .viewBox() bound reference, and its size is defined by .width() and .height(). The behaviour of width and height depends on .patternUnits() configuration (by default is 'objectBoundingBox'), but we usually need to configure it as 'userSpaceOnUse'. With this configuration, height and width are references to the element's coordinate system that uses the pattern.