×

CSS Gradient

CSS Gradient: The CSS gradient property is applied to show the smooth transition inside two specified colors or more than two specified colors.

Need of CSS Gradient

The following are a few reasons why CSS gradient is used:

  • We do not have to apply images to show transition effects.
  • The bandwidth and download time usage may be reduced also.
  • It can give a better appearance to an element if zoomed because any gradient is produced by a browser.

Following are two types of CSS3 gradients:

  1. Radial gradients
  2. Linear gradients

Linear Gradient

 The linear gradient in CSS3 goes left, right, up, down, and diagonally. To design the linear gradient in CSS3, we should have to specify two or more than two color stops. These are any color which can be applied to make the smooth transition. The direction and starting point can be included with any gradient effect also.

background: linear-gradient (direction, color-stop1, color-stop2.....);  
  1. Linear Gradient: (Top-Bottom)

The linear gradient from top to bottom is a default CSS linear gradient. Following is an illustration of the linear gradient, and it will start from the top. It will start blue and the transitions to the yellow.

Example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#grad1
{ 
height: 100px; 
background: -webkit-linear-gradient(blue, yellow); /* For browser Safari 5.1 to 6.0 */ 
background: -o-linear-gradient(blue, yellow); /* For browser Opera 11.1 to 12.0 */ 
background: -moz-linear-gradient(blue, yellow); /* For browser Firefox 3.6 to 15 */ 
background: linear-gradient(blue, yellow); /* Standard syntax (should be last) */ 
} 
</style> 
</head> 
<body> 
<h3> Linear Gradient (Top-Bottom) </h3> 
<p> This linear gradient will be started from the top. It will start blue, transitioning to yellow: </p>  
<div id="grad1"></div> 
</body> 
</html> 

Output:

CSS Gradient
  1. Linear Gradient: (Left-Right)

The following illustration displays the CSS linear gradient. It will start from the left side and proceed to the right side. It will start blue from the left and the transitioning to the green.

Example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#grad1
{ 
height: 100px; 
background: -webkit-linear-gradient(left, blue, yellow); /* For browser Safari 5.1 to 6.0 */ 
background: -o-linear-gradient(right, blue, yellow); /* For browser Opera 11.1 to 12.0 */ 
background: -moz-linear-gradient(right, blue, yellow); /* For browser Firefox 3.6 to 15 */ 
background: linear-gradient(to right, blue, yellow); /* Standard syntax (should be last) */ 
} 
</style> 
</head> 
<body> 
<h3> Linear Gradient (Left-Right) </h3> 
<p> This linear gradient will be started from the left. It will start blue, transitioning to yellow: </p> 
<div id="grad1"></div> 
</body> 
</html> 

Output:

CSS Gradient
  1. Linear Gradient: (Diagonal)

When we describe the vertical and horizontal starting positions, we can create any linear-gradient diagonal.

Example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#grad1
{ 
height: 100px; 
background: -webkit-linear-gradient(left top, blue, yellow); /* For browser Safari 5.1 to 6.0 */ 
background: -o-linear-gradient(bottom right, blue, yellow); /* For browser Opera 11.1 to 12.0 */ 
background: -moz-linear-gradient(bottom right, blue, yellow); /* For browser Firefox 3.6 to 15 */ 
background: linear-gradient(to bottom right, blue, yellow); /* Standard syntax (should be last) */ 
} 
</style> 
</head> 
<body> 
<h3> Linear Gradient (Diagonal) </h3> 
<p> This linear gradient will be started from the left. It will start blue, transitioning to yellow: </p> 
<div id="grad1"></div> 
</body> 
</html> 

Output:

CSS Gradient

Radial Gradient

We should have to represent at least two of the color stops for making the radial gradient. This gradient can be represented through its center.

background: radial-gradient(shape size at position, start-color, ..., last-color);   
  1. Radial Gradient: (Color Stops, i.e., evenly spaced)

Color Stops, i.e., evenly spaced, is the default CSS radial gradient. It has default shapes, which can be position in the center, eclipse, size in the farthest- carner.

Example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#grad1
{ 
height: 150px; 
width: 200px; 
background: -webkit-radial-gradient(blue, yellow, green); /* For browser Safari 5.1 to 6.0 */ 
background: -o-radial-gradient(blue, yellow, green); /* For browser Opera 11.6 to 12.0 */ 
background: -moz-radial-gradient(blue, yellow, green); /* For browser Firefox 3.6 to 15 */ 
background: radial-gradient(blue, yellow, green); /* Standard syntax (should be last) */ 
} 
</style> 
</head> 
<body> 
<h3>Radial Gradient - Color Stops, i.e., Evenly Spaced </h3> 
<div id="grad1"></div> 
</body> 
</html> 

Output:

CSS Gradient
  1. Radial Gradient: (Color Stops, i.e., differently spaced)

Example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#grad1
{ 
height: 150px; 
width: 200px; 
background: -webkit-radial-gradient(blue 5%, yellow 15%, green 60%); /* For browser Safari 5.1 to 6.0 */ 
background: -o-radial-gradient(blue 5%, yellow 15%, green 60%); /* For browser Opera 11.6 to 12.0 */ 
background: -moz-radial-gradient(blue 5%, yellow 15%, green 60%); /* For browser Firefox 3.6 to 15 */ 
background: radial-gradient(blue 5%, yellow 15%, green 60%); /* Standard syntax (should be last) */ 
} 
</style> 
</head> 
<body> 
<h3>Radial Gradient - Color Stops, i.e., Differently Spaced </h3> 
<div id="grad1"></div> 
</body> 
</html> 

Output:

CSS Gradient

Related Topics

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Syntax

The CSS syntax contains the selector and the declaration block, which will be clearer with the following example: Selector: A CSS selector specifies the HTML tag we wish to style. A selector can be...

2 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

4 minutes read.

CSS Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

5 minutes read.

CSS Box-shadow

CSS Box-shadow This property is referred to include effects as shadow-like around an element’s frame. Syntax box-shadow: h-offset v-offset blur spread color |inset|inherit|none; Property values Following are the various property values which can be used...

3 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

How to edit CSS in WordPress

Developing a new website or blog is a difficult undertaking. We want to create something that the consumers will adore, but we might not want the setting to take months and...

7 minutes read.

CSS Checkbox style

CSS Checkbox style: It is an element of HTML, which is used to get input from various users. It is difficult to style any checkbox. However, some elements make it...

6 minutes read.

CSS Color

CSS Colors: The CSS color property is used for setting the HTML element’s color. The color of the fonts and the color of the background can be set-up by using...

5 minutes read.