# gradient

The gradient image type `<gradient>` is used to represent transitions between two or more colors.

`<gradient>` has no intrinsic dimensions; that is, no intrinsic or preferred dimensions, nor preferred ratios. Its actual size depends on the size of its padding element.

This data type is typically used for properties such as `background`, `background-image`, `background-color`, etc.

## Grammar

The `<gradient>` data type is defined by the following gradient functions.

### Linear Gradient

The color values ​​transition gradually along an implicit straight line. Produced by `linear-gradient()`.

````css
/* The gradient axis is 45 degrees, from blue to red */
linear-gradient(45deg, blue, red);
````

````css
/* From bottom right to top left, from blue to red */
linear-gradient(to left top, blue, red);
````

````css
/* From bottom to top, the gradient starts with blue, starts with green gradient at 40% of the height, and ends with red */
linear-gradient(0deg, blue, green 40%, red);
````

#### Standard syntax

````css
linear-gradient([ <angle> | to <side-or-corner> ,]? <color-stop> [ , <color-stop> ]+ )
````
#### can be filled

- `<side-or-corner>` describes the starting point position of the gradient line.

It contains `to` and **two keywords**: the first indicates the horizontal position left or right, and the second indicates the vertical position top or bottom. The order of keywords has no effect and is optional.

The values ​​`to top`, `to bottom`, `to left` and `to right` are converted to angles `0`, `180`, `270` and `90` degrees. The rest of the values ​​are converted to an angle rotated clockwise from the top center. The end point of the gradient line is symmetrical to the center of its start point.

- `<angle>` specifies the direction (or angle) of the gradient with an angle value. The angle increases clockwise.

- `<color-stop>` consists of a `<color>` value followed by an optional end position (which can be a percentage value or `<length>` along the gradient axis).

### Radial Gradient

Color values ​​spread out from a central point (the origin) and gradually transition to other color values. Produced by the `radial-gradient()` function.

````css
/* Gradient from the center to all around */
radial-gradient(#e66465, #9198e5);
````

````css
/* Gradient from edge tangent */
radial-gradient(closest-side, #3f87a6, #ebf8e1, #f69d3c);
````

````css
/* circular gradient */
radial-gradient(circle at 100%, #333, #333 50%, #eee 75%, #333 75%);
````

````css
/* ellipse gradient */
radial-gradient(ellipse at top, #e66465, transparent);
````
#### Standard syntax

````css
radial-gradient(
  [ [ circle || <length> ][ at <position> ]? , |
    [ ellipse || [ <length> | <percentage> ]{2} ] [ at <position> ]? , |
    [ [ circle | ellipse ] || <extent-keyword> ] [at <position> ]? , |
    at <position> ,
  ]?
  <color-stop> [ , <color-stop> ]+
)
````

#### value

- `<position>` `<position>` is similar to `background-position` or `transform-origin`. As default, the default is the center point.

- `<shape>` The shape of the gradient. Circle (`circle`) or oval (`ellipse`). The default is Ellipse.

- `<size>` determines the size of the final shape of the gradient.

- `<extent-keyword>` When the final shape size of the gradient is an infinite extension in a certain direction, rather than a finite line segment, a keyword can be used to describe the size of the gradient shape, the default is `farthest-corner`.

| keywords             | describe                                                       |
| --------------- | -------------------------------------------------------- |
| closest-side    | The edge shape of the gradient is tangent to the side of the container that is closest to the gradient center point (circle) or at least tangent to the vertical and horizontal sides closest to the gradient center point (ellipse). |
| closest-corner  |The edge shape of the gradient intersects the container's corner closest to the center point of the gradient.                               |
| farthest-side   | Contrary to closest-side, the edge shape is tangent to the side of the container furthest from the center point of the gradient (or the furthest vertical and horizontal sides).    |
| farthest-corner | The edge shape of the gradient intersects the corner of the container furthest from the center point of the gradient.                               |

- `<color-stop>` Same as `linear-gradient` description.