Background Image Color Overlay | Create a Filter Look with CSS

css_color_filter_overlay

To add a color overlay to the background image, I am going to use CSS.

 

First of all, adding a CSS background image color overlay is the most dynamic way of creating tinted web page images. It became popular to many websites which appear in homepage as banners.

 

Example:

css-background-image-color-overlay2

 

The great thing about adding background image color overlay is that you can just change any image (normal image without filter) dynamically and publish it on your website with filter, thanks to CSS.

 

So, how to do it?

 

Watch the video or continue reading.

 

 

See also:

 

Add a background property

(Yes not a background-image or background-color).

 

Within the background property, I add a linear gradient and a URL to the image.  I am using a linear-gradient background with transparency.

 

 background:
   linear-gradient(
   rgba (255, 255, 255, 0.5), 
   rgba (255, 255, 255, 0.5)
   ), 
   url(image.jpg)

 

In one CSS property, I need to set two backgrounds. The first one is the linear-gradient color and the second is the actual image.

 

Because I need to add transparency for the background color opacity, I will define RGBA inside the linear gradient.

 

Example:

linear-gradient(
   rgba (255, 255, 255, 0.5), 
   rgba (255, 255, 255, 0.5)
   );

 

The RGBA is an RGB color with an alpha channel. The alpha channel must be set between 0.0 to 1.0. It is the last parameter of the RGBA. The RGBA parameters are composed of red, green, blue, alpha.

Example: rgba (255, 255, 255, 0.5)

 

How to choose and get a color?

 

To make it easier for you to choose the color, create your web page document copying the code from here. Open it in the browser.

 

Developer tool in your browser is your friend. Right-click and inspect your web page (or CTRL+SHIFT+I).

 

On your div with the background style, click on the colored square or circle and a color picker will appear. Choose your color by dragging into the palette.

 

color-box-22bulbjungle-css-background-image-color-overlay2

 

Change the opacity of the color you’ve picked, that is important so we can mimic the overlay or color filter effect in photoshop with our background image.

 

You can also use CSS Gradient Generator from sites like colorzillacssmatic, or cssportal.

 

See the jsfiddle:

Use the background-blend-mode

Are you familiar with Photoshop blend modes?

 

Well, I can also blend our background but with CSS.

 

I can also use the linear-gradient without the transparency and add a background-blend-mode: soft-light;

 

The CSS code should look like this:

.block {
 height: 350px;
 background: linear-gradient(yellow, yellow), url(image.jpg);
 background-size: cover;
 text-align: center;
 background-blend-mode: soft-light;
}

 

As a result, the image and the color blended together in soft-light. Unlike the other way in which I can adjust the opacity.




 

You can experiment by adding different value into the background-blend-mode property.

 

background-blend-mode values include:

  • normal
  • multiply
  • screen
  • overlay
  • darken
  • lighten
  • color-dodge
  • saturation
  • color
  • luminosity

 

CSS Background image color overlay in hover

 

Add a background image color overlay if the user hovers over the image.

 

 

In conclusion, adding the color filter effect can be done in two ways. The first is through a background property with the linear gradient and image url.

 

The other is to add a solid color within the parameter of linear-gradient and add the background-blend-mode property.

 

Creating a Hero Image with color filter overlay on hover

 

Hero image is a large website banner image. It is composed of the background image, texts and even a button.

 

Learn how to create your hero image with CSS background image color overlay by watching the video below:

You can use either of the two techniques to add the effect into your CSS background image.

 

Hi, did you know that we have a youtube channel? It's called Garnatti one. Check it out!
I believe that education must be free to everyone. Feel free to share.

One Comment;

    Leave a comment

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