For working professionals
For fresh graduates
More
1. Introduction
6. PyTorch
9. AI Tutorial
10. Airflow Tutorial
11. Android Studio
12. Android Tutorial
13. Animation CSS
16. Apex Tutorial
17. App Tutorial
18. Appium Tutorial
21. Armstrong Number
22. ASP Full Form
23. AutoCAD Tutorial
27. Belady's Anomaly
30. Bipartite Graph
35. Button CSS
39. Cobol Tutorial
46. CSS Border
47. CSS Colors
48. CSS Flexbox
49. CSS Float
51. CSS Full Form
52. CSS Gradient
53. CSS Margin
54. CSS nth Child
55. CSS Syntax
56. CSS Tables
57. CSS Tricks
58. CSS Variables
61. Dart Tutorial
63. DCL
65. DES Algorithm
83. Dot Net Tutorial
86. ES6 Tutorial
91. Flutter Basics
92. Flutter Tutorial
95. Golang Tutorial
96. Graphql Tutorial
100. Hive Tutorial
103. Install Bootstrap
107. Install SASS
109. IPv 4 address
110. JCL Programming
111. JQ Tutorial
112. JSON Tutorial
113. JSP Tutorial
114. Junit Tutorial
115. Kadanes Algorithm
116. Kafka Tutorial
117. Knapsack Problem
118. Kth Smallest Element
119. Laravel Tutorial
122. Linear Gradient CSS
129. Memory Hierarchy
133. Mockito tutorial
134. Modem vs Router
135. Mulesoft Tutorial
136. Network Devices
138. Next JS Tutorial
139. Nginx Tutorial
141. Octal to Decimal
142. OLAP Operations
143. Opacity CSS
144. OSI Model
145. CSS Overflow
146. Padding in CSS
148. Perl scripting
149. Phases of Compiler
150. Placeholder CSS
153. Powershell Tutorial
158. Pyspark Tutorial
161. Quality of Service
162. R Language Tutorial
164. RabbitMQ Tutorial
165. Redis Tutorial
166. Redux in React
167. Regex Tutorial
170. Routing Protocols
171. Ruby On Rails
172. Ruby tutorial
173. Scala Tutorial
175. Shadow CSS
178. Snowflake Tutorial
179. Socket Programming
180. Solidity Tutorial
181. SonarQube in Java
182. Spark Tutorial
189. TCP 3 Way Handshake
190. TensorFlow Tutorial
191. Threaded Binary Tree
196. Types of Queue
197. TypeScript Tutorial
198. UDP Protocol
202. Verilog Tutorial
204. Void Pointer
205. Vue JS Tutorial
206. Weak Entity Set
207. What is Bandwidth?
208. What is Big Data
209. Checksum
211. What is Ethernet
214. What is ROM?
216. WPF Tutorial
217. Wireshark Tutorial
218. XML Tutorial
CSS linear gradients are a useful tool for generating seamless transitions between two or more colors in web design. With linear gradients, you may alter the direction, beginning and finishing colors, and even locate color stops to fine-tune the gradient effect. This tutorial will provide insights into how to use linear gradients in CSS, including syntax, color stops, direction, and location.
In CSS, a linear gradient creates a seamless transition between two or more colors in a straight line. It is one of three gradient types in CSS, along with radial and conic gradients, and is represented by the linear-gradient() function.
You must provide at least two color stops, the colors you wish to transition between, to build a linear gradient. The gradient's direction may also be customized by providing a direction or angle. Linear gradients flow from top to bottom by default, but you may modify the direction to generate horizontal, diagonal, or any other gradient you choose.
A gradient is a mathematical concept that describes a function's direction and rate of change. It is used in numerous fields, including calculus, linear algebra, and machine learning, to determine the slope or steepness of a function.
Linear gradient in CSS is a method to exhibit seamless transitions between two or more specified colors in CSS. CSS has three types of gradients: linear, radial, and conic.
The linear-gradient() method generates a gradient that travels down, up, left, right, or diagonally. To create a linear background gradient from red to orange, you can use the following code:
background-image: linear-gradient(red, orange);
To create a linear gradient from left to right with the colors of the rainbow, you can use the following code:
background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
The radial-gradient() method produces a gradient that radiates from a central point.
To create a radial gradient from purple to orange, you can use the following code:
background-image: radial-gradient(purple, orange);
To create a radial gradient that starts from the center and goes to the edges of the element, you can use the following code:
background-image: radial-gradient(circle, red, yellow, green);
The conic-gradient() function generates a gradient with color transitions that are spun around a central point.
To create a conic gradient color from red to yellow to green, you can use the following code:
background-image: conic-gradient(red, yellow, green);
To create a conic gradient that starts from the center and goes to the edges of the element, you can use the following code:
background-image: conic-gradient(circle, red, yellow, green);
CSS gradient color palettes like checkerboards and pie charts can also create interesting effects. They can also be used to create responsive image effects, such as fading effects
To make a linear gradient in CSS, use the linear-gradient() function. The following is the syntax for making a linear gradient:
background-image: linear-gradient(direction, color1, color2, ...);
direction: This option defines the beginning position, direction, and gradient effect. It may be defined as a keyword (to the top, bottom, left, or right) or an angle (45 degrees, 135 degrees, and so on).
color1, color2, and so on: These parameters include the gradient's color values. You may specify numerous color stops to create a seamless transition between hues.
Here's an example of a linear gradient that goes from red to yellow to blue and begins at the top:
background-image: linear-gradient(red, yellow, blue);
Linear gradients are gradients that feature a gradual transition of colors in distinct patterns. They are mainly used for backgrounds as an image. Before CSS gradients, developers had to employ pictures to generate similar effects, which had the major downside of slowing down the website’s speed. But using CSS gradients, the performance, as well as resolution, were both enhanced and simplified.
The W3C standards for linear CSS gradients are supported by the most recent versions of all the major browsers, making them a far more advantageous option because of their cross-browser compatibility. The following is the syntax for producing a linear gradient:
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
The direction parameter provides the gradient's direction, which may be in degrees, gradients, or keywords. The color-stop parameters define the gradient's color stops, which may be either a percentage or a color name/hex code.
According to Can I Use, as of June 2017, 93.75% of Internet traffic is on browsers that support unprefixed linear gradients (97.2% as of December 2022). However, earlier versions of specific browsers need vendor prefixes to allow linear gradients. The following prefixes are used for different browsers:
For example, to build a linear gradient that is compatible with previous versions of Chrome and Safari, the following code may be used:
background-image: -webkit-gradient(linear, left bottom, right top, color-stop(0%, red), color-stop(100%, blue));
To create a linear gradient that is compatible with Internet Explorer, the following code can be used:
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FF0000', endColorstr='#0000FF', GradientType=0);
IE filters are a proprietary Microsoft technology that enables developers to add visual effects to HTML elements. One of the filters offered is the gradient filter, which may produce linear gradients in Internet Explorer (v 5.5-9). The syntax for utilizing the gradient filter is as follows:
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FF0000', endColorstr='#0000FF', GradientType=0);
The startColorstr and endColorstr arguments provide the gradient's start and end colors, respectively. The GradientType option, which may be 0 (horizontal) or 1 (vertical), determines the kind of gradient.
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 130px;
width: 220px;
background-color:pink;
background-image: radial-gradient(closest-side at 60% 55%, red, blue);
}
</style>
</head>
<body>
<h1>Radial Gradient - upGradTutorial</h1>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 220px;
width: 220px;
background-color: blue;
background-image: conic-gradient(from 90deg, red, blue, green);
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Conic Gradient - upGradTutorial!</h1>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 220px;
background-image: repeating-linear-gradient(blue, yellow 10%, green 20%);
}
</style>
</head>
<body>
<h3>Repeating Linear Gradient in upGradTutorial!</h3>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 220px;
width: 220px;
background-color: red;
background-image: repeating-conic-gradient(blue 10%, yellow 20%);
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Repeating Conic Gradient in upGradTutorial!</h1>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 220px;
background-image: repeating-radial-gradient(blue, yellow 10%, green 15%);
}
</style>
</head>
<body>
<h3>Repeating Radial Gradient in upGradTutorial!</h3>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
img {
display: block;
font-family: sans-serif;
font-weight: 300;
height: auto;
line-height: 2;
position: relative;
text-align: center;
width: 100%;
}
img::before {
content: "Sorry, this image is unavailable.";
display: block;
margin-bottom: 8px;
}
img::after {
content: "(url: " attr(src) ")";
display: block;
font-size: 12px;
}
</style>
</head>
<body>
<h2>Rounded Image</h2>
<img src="paris.jpg" alt="Paris" width="300" height="300">
</body>
</html>
Customizing gradients in CSS allows you to create unique and visually appealing backgrounds and effects for your web elements. Gradients can be customized by adjusting various parameters such as colors, positions, angles, and color stops. Here's a guide on how to customize gradients in CSS:
Linear gradients transition colors along a straight line. Here's an example of a linear gradient customized with different color stops:
.linear-gradient {
width: 300px;
height: 200px;
background-image: linear-gradient(45deg, #ff0000, #00ff00, #0000ff);
}
In this example:
45deg sets the angle of the gradient to 45 degrees.
#ff0000, #00ff00, and #0000ff are color stops.
Radial gradients transition colors outward from a central point. Here's an example of a radial gradient customized with different shapes and color stops:
.radial-gradient {
width: 200px;
height: 200px;
background-image: radial-gradient(circle, #ff9900, #ffffff 70%, #0099ff);
}
In this example:
circle sets the shape of the gradient to a circle.
#ff9900, #ffffff, and #0099ff are color stops.
70% specifies the point where the transition between colors occurs.
Repeating gradients allow you to create patterns with repeated color transitions. Here's a customized example of a repeating linear gradient:
.repeating-linear {
width: 300px;
height: 200px;
background-image: repeating-linear-gradient(45deg, #ff0000, #00ff00 20px, #0000ff 20px, #ffffff 40px);
}
In this example:
45deg sets the angle of the gradient to 45 degrees.
#ff0000, #00ff00, #0000ff, and #ffffff are color stops.
20px defines the size of each stripe.
You can customize the direction and position of gradients. For example, a linear gradient can have directions like to top, to bottom, to left, or to right. A radial gradient can be positioned using keywords like center, top left, bottom right, etc.
.linear-top {
background-image: linear-gradient(to top, #ff0000, #00ff00);
}
.radial-center {
background-image: radial-gradient(circle at center, #ff9900, #0099ff);
}
You can use transparent colors and adjust color stops to create smooth transitions and overlays.
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 220px;
background-color: red;
background-image: linear-gradient(blue, yellow);
}
</style>
</head>
<body>
<h1>Linear Gradient in upGradTutorial!</h1>
<div id="grad1"></div>
</body>
</html>
Mastering the technique of creating and manipulating linear gradients in CSS offers up a world of creative possibilities for web designers and developers alike. Knowing the syntax, direction, color stops, and numerous gradient kinds, you can quickly add depth, dimension, and visual intrigue to your online applications.
Whether constructing delicate overlays for beautiful aesthetics or crafting vivid and dynamic backdrops that fascinate consumers, the adaptability of linear gradients allows you to bring your design dreams to reality. With the information from this tutorial, you are well-equipped to explore, create, and improve your web designs by smoothly incorporating attractive linear gradients.
1. What is a text color gradient in CSS?
A text CSS color gradient is an attribute that adds a gradient to an element's text.
2. What is a border gradient in CSS?
A border gradient is a CSS property that adds a gradient to an element's border.
3. What is a radial gradient in CSS?
A radial gradient is a CSS function that generates a gradient in a circular or elliptical form that transitions between two or more colors.
4. How to use a linear gradient in CSS color code?
You must define at least two color stops in CSS to create a linear gradient. Color stops are the colors between which you want to create smooth transitions. You may provide a starting point, direction (or an angle), and gradient effect.
Author
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.