Gradient - color linear transformation in CSS
Gradient - the color of linear transformation in CSS allows the creation of colored elements in the background as the transition effects between two or more specified colors.
There are 2 types of CSS supported by CSS:
- Linear Gradient: Scans colors starting from one side, can be up, down, left, right, diagonal.
- Radial Gradient: Scanning colors comes from the mind.
Linear Gradient
To create a Linear Gradient, you need to define at least two stops of color . Color stops are the colors you want to display forwards.
You can specify additional directions (direction) or angle (angle) to start the transition effect. Some directions like:
- to top
- to bottom
- to bottom right
- to right
- to left
- .
Syntax Linear Gradient
background-image: linear-gradient(direction, color-stop1, color-stop2, .);
Parameters:
- direction: Direction to determine the starting point of the transition effect (to bottom, to top, to right, to left, to bottom right .)
- color-stop1, color-stop2 . : Color stops. A color stop includes a color value and an optional stop position (in percentages from 0% to 100% or along the gradient length).
For example
1. Linear Gradient - Top to Bottom (Default direction)
The following example shows a Linear Gradient starting from the top (top). Linear Gradient starts with purple and changes to pink:
#grad {
background-image: linear-gradient(purple, pink);
}
Linear Gradient - Top to Bottom
Note : Internet Explorer 9 and earlier versions do not support gradients.
2. Linear Gradient - Left to Right
The following example shows a Linear Gradient starting from the left. Linear Gradient starts with purple and changes to pink:
#grad {
background-image: linear-gradient(to right, purple, pink);
}
Linear Gradient - Left to Right
3. Linear Gradient - Diagonal (Diagonal Direction)
You can create a diagonal gradient by defining both vertical and horizontal directions.
The following example shows a Linear Gradient starting from the top left (and going to the bottom right). Linear Gradient starts with purple and changes to pink:
#grad {
background-image: linear-gradient(to bottom right, purple, pink);
}
Linear Gradient - Diagonal
Use Angle (Angle)
You can choose another way to format the gradient that is to use an angle instead of defining the direction (to bottom, to top, to right, to left, to bottom right .) using the following syntax :
background-image: linear-gradient(angle, color-stop1, color-stop2);
Parameters:
- Angle: the angle determined by the horizontal line and gradient line going counterclockwise. In other words, 0deg will create bottom to top Gradient, 90deg will create left to right Gradient.
Example: Use angle in Linear Gradient
#grad {
background-image: linear-gradient(-90deg, purple, pink);
}
Linear Gradient - Use Angle
Use multiple color stops
The following example shows a Linear Gradient (from top to bottom) with multiple color stops:
3 stops of color are equally spaced
#grad {
background-image: linear-gradient(indigo, crimson, pink);
}
7 stops color equally
#grad {
background-image: linear-gradient(crimson, lightsalmon, gold, seagreen,
midnightblue, indigo, violet);
}
3 color stops are not evenly spaced
#grad {
background-image: linear-gradient(crimson 10%, indigo 55%, violet 80%);
}
Note: If you do not specify a% value after each color stop, the gradient is automatically spaced.
Full code:
Linear Gradients - Use multiple color stops
3 color stops are equally spaced:
7 color stops are equally spaced:
3 color stops are not evenly spaced
7 color stops are equally spaced from left to right
#grad {
background-image: linear-gradient(to right, crimson, lightsalmon, gold,
seagreen, midnightblue, indigo, violet);
}
Use Transparency
In addition to the above gradients, you can use transparency - transparency in CSS to create gradient gradation effects.
To add transparency to the color, you use RGBA Color as introduced in the color-intensive lesson to identify color stops. The last parameter in RGBA () specifies the opacity / transparency of the color, with a value between 0.0 and 1.0, the smaller the value, the more transparency.
For example: A background linear gradient starts with a completely transparent color and gradually changes to purple:
#grad {
background-image: linear-gradient(to right, rgba(88,37,123,0),
rgba(88,37,123,1));
}
Linear Gradient - Transparency
Repeat a Linear Gradient
The repeating-linear-gradient () function is used to repeat Linear Gradient.
#grad {
background-image: repeating-linear-gradient(indigo, crimson 10%, pink 20%);
}
#grad {
background-image: repeating-linear-gradient(45deg, indigo, crimson 7%,
pink 10%);
#grad {
background-image: repeating-linear-gradient(190deg, indigo, crimson 7%,
pink 10%);
#grad {
background-image: repeating-linear-gradient(90deg, indigo, crimson 7%,
pink 10%);
Full code:
Repeating Linear Gradient
Corner 45deg:
Angle 190deg:
90deg angle:
Radial Gradient
Radial Gradient creates a transition effect from the center of the element .
To create a Radial Gradient you must also specify at least two color stops.
Radial Gradient syntax
background-image: radial-gradient(shape-size-at position, start-color. last-color);
Parameters:
- shape: Determine the shape of the gradient. Possible values:
- ellipse (default)
- circle
- size: Determine the size of the gradient. Possible values:
- farthest-corner (default)
- closest-side
- closest-corner
- farthest-side
- position: Determine the position of the gradient, the default is from the center.
- start-color . last-color: Color stops. A color stop includes a color value and an optional stop position (in percentages from 0% to 100% or along the gradient length).
For example
1. Stops colors equally
#grad {
background-image: radial-gradient(bisque, crimson, indigo);
}
Radial Gradient - Stops colors equally
2. Color stops are not evenly spaced
#grad {
background-image: radial-gradient(bisque 5%, crimson 20%, indigo 65%);
}
Radial Gradient - Color stops are not evenly spaced
Shape parameter value
The shape parameter is used to determine the shape of the gradient , which can be either a circle value or an ellipse.
For example, a gradient originating from the center with a shape is a circle:
#grad {
background-image: radial-gradient(circle, bisque, crimson, indigo);
}


Radial Gradient - Shape
Size parameter value
The size parameter determines the size of the gradient. Possible values:
- farthest-corner (default)
- closest-side
- closest-corner
- farthest-side
closest-side:
#grad1 {
background-image: radial-gradient
(closest-side at 60% 55%, bisque,
crimson, indigo);
}
farthest-side:
#grad2 {
background-image: radial-gradient
(farthest-side at 60% 55%, bisque,
crimson, indigo);
}


closest-corner:
#grad3 {
background-image: radial-gradient
(closest-corner at 60% 55%, bisque,
crimson, indigo);
}
farthest-corner (default):
#grad4 {
background-image: radial-gradient
(farthest-corner at 60% 55%, bisque,
crimson,indigo);
}


Full code:
Radial Gradient - Use the size parameter
closest-side:
farthest-side:
closest-corner:
farthest-corner (default):
Repeat a Radial Gradient
The repeating-radial-gradient () function is used to repeat the Radial Gradient.
#grad {
background-image: repeating-radial-gradient(bisque, crimson 10%, indigo 15%);
}
Repeat a Radial Gradient
Previous lesson: Deep understanding of Color in CSS
Next lesson: Shadow effect in CSS
You should read it
- How to Create a Gradient in Photoshop
- Synthesize the most beautiful CSS Background Gradient template
- How to use the Radial Gradient filter in Lightroom
- Apply gradient effects to background colors in PowerPoint
- How to Make a Gradient in MS Paint
- Instructions for creating Gradient effects in Word
- Download the new Gradient palette for Photoshop
- Coloring gradients in Photoshop - Guidelines for using gradients in Photoshop
May be interested
- How to Create a Gradient in Google Slideswhen making a slideshow presentation on google slides, many people make their backgrounds and textboxes a single solid color. however, creating and using gradients on google slides can make your presentation stand out. go to...
- Linear search algorithm (Linear Search)linear search is a very basic search algorithm. in this type of search, a continuous search operation takes place through every element. each element is checked and if any connection is found, that particular element is returned; if not found, the search process continues until the data is searched.
- FORECAST function - The function returns a value along a linear trend in Excelforecast function: the function performs the calculation or prediction of a future value by using current values using linear regression. in excel 2016 this function is replaced by forecast.linear function. syntax: forecast (x, known_ys, known_xs)
- How to use the Radial Gradient filter in Lightroomthe radial gradient filter is a great feature if you want to edit specific aspects of your photo in more detail.
- How to use gradient colors for Canva textgradient color ranges bring artistic effect to images and text, helping the content stand out in the design.
- How to Make a Blend in Microsoft Paintalthough microsoft paint is a relatively basic program, it has a surprising amount of functionality, especially when it comes to creating blends of color. if you're trying to create a stunning gradient or a variety of custom colors to give...
- Chuck Market launches Converse shoe model Chuck 70 automatically changes color according to lightrecently, converse has partnered with chinatown market to release a new collection: the twin converse chuck 70 legend 'can change color flexibly under sunlight'.
- The terminology of color, wheel color and skill used to colorhave you ever wondered how designers can find the perfect color combination? in this article, quantrimang will work with you to learn useful terms about colors. invites you to read the track
- What is the profile color?color profile determines the color we take with the camera and sees it on the screen. it controls the colors used and helps to bring consistency between devices.
- Instructions for filming mermaid transformation videos on TikToktiktok has just updated the ai mermaid video transformation effect so that users have more unique transformation models to record videos.