Setting a Background Image Opacity in CSS


Apply opacity to a background image by using a pseudo-element for the background.

Source Code

.background-opacity::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('image.jpg') no-repeat center center;
    background-size: cover;
    opacity: 0.5;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments