All TalkersCode Topics

Follow TalkersCode On Social Media

Black Overlay On Background Image CSS

Last Updated : Jul 1, 2023

Black Overlay On Background Image CSS

In this article we will show you the solution of black overlay on background image CSS, here we achieving result through object-fit and filter property in css styles.

First you need to set particular image as background of landing page and then you have to implement black color overlay on that image.

There is another exist if you want to try that keep stay with us.

Separately you need to create black color mirroring glass effect then bind that with background image.

Step By Step Guide On Black Overlay On Background Image CSS :-

In this program you need to insert image with id or class attributes or element name.

Because it help you to apply styles to the image element. Here we have to set this image as background through css styles.

So attribute is essential and using 'object-fit,width,height' properties we sets this image to fit background size.

With the help of filter property here we creating black overlay effect on image.

<!Doctype html>
        <title>Bg With Black Overlay</title>
                margin: 0;
            header img{
                width: 100vw;
                height: 100vh;
                object-fit: cover;
                filter: brightness(.4);
            <img src="im.jpg" alt="background image">
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is containing information about webpage and if you need any external file those links are declared here. <title> tag is used for set the webpage title.
  4. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  5. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  6. In body section first we defined internal css style method to apply styles to image tag. As foremost step we sets body to value '0'. To collapse default margin, then we pointing image tag through 'header img' line.
  7. Then we sets image width and height to value 100, to expand the image we using object-fit with value 'cover'- it will covers deaktop screen size, brightness value .4 creates dark shadown on image.
  8. In this way we achieving result. Then within header tag we defined img tag- helps us to insert image on body of webpage. The value 'im.jpg' refers image name with extension, alt - refers alternate name for image that will display when image fails.
  9. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion we are able to know how to implement black overlay on image using css.

When we executes this program on webpage of browser you can see background image with black overlay as output.

Surely image will vary, but the result same. Make sure your image path perfectly retrieved otherwise you cannot see image in output.

Take any image in your local storage then copy its path and paste it in src attribute value.

I hope this article on black overlay on background image CSS helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials