from an answer of mine at How to add a color overlay to a background image? marked as a duplicate of that question where no pseudo element ,nor extra element is required.
That duplicate, right here and after a few years, is still missing the background-blend-mode
property , widely implemented nowdays (It lays below the multiple background and inset shadow examples).
So here is about my answer out there, answer that gives you 3 easy ways without extra markup nor pseudos :
At first , i saw two easy options at that time (2016, those two option are also within answers standing here too, so nothing really new to add about these, ... mind the third one if you already read other answers about bg and box-shadow):
Examples given out there where:
gradient option:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Images/Using_CSS_gradients
CSS gradients are represented by the <gradient>
data type, a special type of <image>
made of a progressive transition between two or more colors. You can choose between three types of gradients: linear (created with the linear-gradient()
function), radial (created with the radial-gradient()
function), and conic (created with the conic-gradient()
function). You can also create repeating gradients with the repeating-linear-gradient()
, repeating-radial-gradient()
, and repeating-conic-gradient()
functions.
Gradients can be used anywhere you would use an <image>
, such as in backgrounds. Because gradients are dynamically generated, they can negate the need for the raster image files that traditionally were used to achieve similar effects. In addition, because gradients are generated by the browser, they look better than raster images when zoomed in, and can be resized on the fly.
html {
min-height:100%;
background:linear-gradient(0deg, rgba(255, 0, 150, 0.3), rgba(255, 0, 150, 0.3)), url(https://picsum.photos/id/100/2500/1656);
background-size:cover;
}
shadow option:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
The box-shadow
CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.
inset
If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content). The presence of the inset keyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content.
html {
min-height: 100%;
background: url(https://picsum.photos/id/100/2500/1656);
background-size: cover;
box-shadow: inset 0 0 0 2000px rgba(255, 0, 150, 0.3);
}
an old codepen of mine with few examples
Now, that third option missing here :
The background-blend-mode
CSS property sets how an element's background images should blend with each other and with the element's background color.
html {
min-height: 100%;
background: url(https://picsum.photos/id/100/2500/1656) rgba(255, 0, 150, 0.3);
background-size: cover;
background-blend-mode: multiply;
}
There is of course and also other valuable ways to do this, depending on your project, CSS libraries used and the few option left over from what you already have. There is almost never a single way/method , but different ways .What matters is to find the option that suits your needs the best and efficiently, the method that you understand/master , the browser specifity, option left over from what already being used if you feel confident with or already have a javascript or a server side function that already can/do that job, use it if its already there. a wheel is a wheel.