1e41f4b71Sopenharmony_ci# Gradient Styles
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_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.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThe development framework supports two gradient styles: linear gradient and repeating linear gradient.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## Linear Gradient/Repeating Linear Gradient
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciTo use the gradient style, you must specify the transition direction and transition color.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci### Transition Direction
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci  You can specify the transition direction through **direction** or **angle**.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci- **direction**: gradient by direction.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci- **angle**: gradient by angle.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci```css
27e41f4b71Sopenharmony_cibackground: linear-gradient(direction/angle, color, color, ...);
28e41f4b71Sopenharmony_cibackground: repeating-linear-gradient(direction/angle, color, color, ...);
29e41f4b71Sopenharmony_ci```
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci### Transition Color
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_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.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Parameters**
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| Name       | Type                                      | Default Value                         | Mandatory  | Description                                      |
39e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---------------------------- | ---- | ---------------------------------------- |
40e41f4b71Sopenharmony_ci| direction | to <side-or-corner>  <side-or-corner> = [left \| right] \|\| [top \| bottom] | to bottom (gradient from top to bottom)| No   | Transition direction. For example, **to left** (gradient from right to left) or **to bottom right** (gradient from upper left corner to lower right corner).|
41e41f4b71Sopenharmony_ci| angle     | <deg>                              | 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.|
42e41f4b71Sopenharmony_ci| color     | <color> [<length>\|<percentage>] | -                            | Yes   | Colors among which smooth transitions are rendered.                     |
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Example**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci1. Gradient from top to bottom (default)
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci   ```css
49e41f4b71Sopenharmony_ci   #gradient {
50e41f4b71Sopenharmony_ci     height: 300px;
51e41f4b71Sopenharmony_ci     width: 600px;
52e41f4b71Sopenharmony_ci     /* Gradient starts from red at the top to green at the bottom. */
53e41f4b71Sopenharmony_ci     background: linear-gradient(red, #00ff00);
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      ![222](figures/222.PNG)
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci3. Gradient from left to right
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci   ```css
71e41f4b71Sopenharmony_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) */
72e41f4b71Sopenharmony_ci   background: linear-gradient(to right, rgb(255, 0, 0) 90px, rgb(0, 255, 0) 60%);
73e41f4b71Sopenharmony_ci   ```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci    ![333](figures/333.PNG)
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci4. Repeating gradient
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci   ```css
80e41f4b71Sopenharmony_ci     /* Repeating gradient from left to right, the area of which is 30 px (60 – 30) and the opacity is 0.5 */
81e41f4b71Sopenharmony_ci     background: repeating-linear-gradient(to right, rgba(255, 255, 0, 1) 30vp,rgba(0, 0, 255, .5) 60vp);
82e41f4b71Sopenharmony_ci   ```
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci   ![444](figures/444.PNG)
85