Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

CSS | Combine background image with gradient overlay

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

CSS gradients allow us to display smooth transitions between two or more colours. They can be added on top of the background image by simply combining the background-image URL and gradient properties.

Syntax:

element {
   background-image: linear-gradient(direction, 
    color-stop1, color-stop2, ...), url('url');
}
element {
   background-image: radial-gradient(direction, 
   color-stop1, color-stop2, ...), url('url');
}

Below are examples illustrating the above approach:

Example 1: Background image with the linear gradient.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>Background Image with Linear Gradient</title>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet"
        href=
    <style>
        .my_bg {
            background-image:
            linear-gradient(45deg,
              rgba(245,70,66, 0.75),
              rgba(8,83,156, 0.75)), url(
            width: 100%;
            height: 280px;
            text-align: center;
              color: #fff;
        }
    </style>
</head>
 
<body>
    <div class="my_bg">
        <h3>This is my background!</h3>
    </div>
</body>
 
</html>

Output:

 

Example 2: Background image with the radial gradient.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>Background Image with Radial Gradient</title>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet"
        href=
    <style>
        .my_bg {
            background-image: radial-gradient(
              rgba(255, 49, 3, 0.896),
              rgba(251, 255, 0, 0.75)), url(
            width: 100%;
            height: 250px;
            text-align: center;
        }
    </style>
</head>
 
<body>
    <div class="my_bg">
        <h4>This is my background!</h4>
    </div>
</body>
 
</html>

Output:

 

HTML is the foundation of web pages and is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.

CSS is the foundation of web pages and is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.


My Personal Notes arrow_drop_up
Last Updated : 13 Jun, 2022
Like Article
Save Article
Similar Reads
Related Tutorials