Change brightness of background-image?

user3227878 picture user3227878 · Jan 26, 2014 · Viewed 75.5k times · Source

I am wondering if it is possible to change the brightness of:

 body{
 background-image:url();
 }

Using HTML/CSS. The reason I would like to change it, is because I just spent a rather long time making the image, but when I put it on website, it is suddenly about twice as bright. I have compared the original file and the file that is input into the website and they are both very much different colours of blue.

Is there any reason for this, and is there a way I can change the brightness?

Thanks.

Answer

Martin Zvarík picture Martin Zvarík · Dec 21, 2017
background:linear-gradient(rgba(255,255,255,0.5), rgba(255,255,255,0.5)), url(myimage.png);

This will put 50% white over the original image.

Linear-gradient function has to be used, otherwise it doesn't work.

Or you can use:

.someObj:after{ content:''; background:rgba(255,255,255,.5); .... }

and this is better for code maintainability.