CSS Gradient Backgrounds

This tutorial walks you through creating gradient backgrounds with CSS for your website.

In this tutorial we’re going to explore how to add a gradient background using CSS. If you’re already familiar with adding a background colour using CSS in this format:

Background: Orange;

Or simply in this format:

Background-colour: Orange;

Then the approach to gradients is fairly similar. You use the background-image tag and set the colours that you’d like to use within the gradient and the additional parameters to set the direction / style of the gradient.

For example:

.class-name {

Background-image: linear-gradient (orange, pink, white);

}

Despite the above being an interesting colour combination it’ll create a steady gradient mixture of those colours.

Let’s say you only want two colours your code would be similar. 

.class-name {

Background-image: linear-gradient (orange, pink);

}

Or you can add further colours to it for example:

.class-name {

Background-image: linear-gradient (orange, pink, purple, white);

}

To further style the gradient that you’ve used you can set the direction of it for example:

.class-name {

Background-image: linear-gradient (to right, orange, pink);

}

The above sets a linear gradient from left to right using the two colours. You can add most CSS positions such as top right etc.

You can alternatively set the angle of the gradient for example: 

.class-name {

Background-image: linear-gradient (100 deg, orange, pink);

}

The above sets the gradient at 100 degrees.

Further styling options can include setting the volume of each colour used within the gradient for example:

.class-name {

Background-image: linear-gradient (to right, orange 75%, pink 25%);

}

Further reading:

Adding CSS to WordPress

We hope this helps you to understand how to  set CSS Gradients on your site using a few simple snippets of CSS code.

We’d appreciate a share or any comments if you found this useful, thanks!

Tech Typed
Tech Typed
Articles: 186

Leave a Reply

Your email address will not be published. Required fields are marked *