1e41f4b71Sopenharmony_ci# Gradient Styles
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciGradient styles are commonly supported and can be set in the **style** attribute or a **.css** file. Gradients enable smooth transition between two or more specified colors.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ciThis framework supports two gradient styles: linear gradient and repeating linear gradient.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Linear Gradient/Repeating Linear Gradient
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciTo use the gradient style, you need to specify the transition direction and transition color.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci### Transition Direction
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciThe available values are as follows:
21e41f4b71Sopenharmony_ci- **direction**: gradient by direction.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci- **angle**: gradient by angle.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci```
26e41f4b71Sopenharmony_cibackground: linear-gradient(direction/angle, color, color, ...);
27e41f4b71Sopenharmony_cibackground: repeating-linear-gradient(direction/angle, color, color, ...);
28e41f4b71Sopenharmony_ci```
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci### Transition Color
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciThe color can be specified in any of the following formats: \#ff0000, \#ffff0000, rgb (255, 0, 0), and rgba (255, 0, 0, 1). At least two colors must be specified.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Parameters**
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci| Style       | Type                                      | Default Value                         | Mandatory  | Description                                      |
38e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---------------------------- | ---- | ---------------------------------------- |
39e41f4b71Sopenharmony_ci| direction | to &lt;side-or-corner&gt;  &lt;side-or-corner&gt; = [left \| right] \| [top \| bottom] | to bottom (gradient from top to bottom)| No   | Transition direction, for example, **to left** (gradient from right to left) or<br>**to bottom right** (gradient from the top left to the bottom right).|
40e41f4b71Sopenharmony_ci| angle     | &lt;deg&gt;                              | 180deg                       | No   | Transition direction, which is the angle between the gradient line and the y-axis (in the clockwise direction), with the geometric center of the element being the origin of coordinates and the horizontal axis being the x-axis.|
41e41f4b71Sopenharmony_ci| color     | &lt;color&gt; [&lt;length&gt;\|&lt;percentage&gt;] | -                            | Yes   | Colors among which smooth transitions are rendered.                     |
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Example**
44e41f4b71Sopenharmony_ci1. Gradient from top to bottom (default)
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci   ```css
47e41f4b71Sopenharmony_ci   #gradient {
48e41f4b71Sopenharmony_ci     height: 300px;
49e41f4b71Sopenharmony_ci     width: 600px;
50e41f4b71Sopenharmony_ci     /* Gradient starts from red at the top to green at the bottom. */
51e41f4b71Sopenharmony_ci     background: linear-gradient(red, #00ff00);
52e41f4b71Sopenharmony_ci   }
53e41f4b71Sopenharmony_ci   ```
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci   
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci![111](figures/111.png)
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci2. Gradient at an angle of 45°
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci   ```css
62e41f4b71Sopenharmony_ci   /* Gradient at an angle of 45°, changing from red to green */
63e41f4b71Sopenharmony_ci     background: linear-gradient(45deg, rgb(255,0,0),rgb(0, 255, 0));
64e41f4b71Sopenharmony_ci   ```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci   
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci![222](figures/222.png)
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci3. Gradient from left to right
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci   ```css
73e41f4b71Sopenharmony_ci   /* Gradient from left to right, which is available in the 270 px width between the left 90 px and the left 360 px (600*0.6) */
74e41f4b71Sopenharmony_ci   background: linear-gradient(to right, rgb(255,0,0) 90px, rgb(0, 255, 0) 60%);
75e41f4b71Sopenharmony_ci   ```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci![333](figures/333.png)
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci4. Repeating gradient
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci   ```css
82e41f4b71Sopenharmony_ci   /* Repeating gradient from left to right, the area of which is 30 px (60 – 30) and the opacity is 0.5 */
83e41f4b71Sopenharmony_ci   background: repeating-linear-gradient(to right, rgba(255, 255, 0, 1) 30px,rgba(0, 0, 255, .5) 60px);
84e41f4b71Sopenharmony_ci   ```
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci![444](figures/444.png)
87