isolation
and inset
for an Image OverlaySee the Pen Low opacity bg-image by Kevin (@kevinpowell) on CodePen.
<div class="low-opacity-bg-image">
<h1>Background image opacity?</h1>
<p>It's possible! ... sort of</p>
</div>
.low-opacity-bg-image {
--bg-image: url("https://images.unsplash.com/photo-1656860444750-dd91d7fecfc7?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTkzODA1OTA&ixlib=rb-1.2.1&q=80");
--bg-image-opacity: 0.25;
display: grid;
place-content: center;
text-align: center;
min-height: 500px;
position: relative;
isolation: isolate;
}
.low-opacity-bg-image::after {
content: "";
position: absolute;
z-index: -1;
inset: 0;
opacity: var(--bg-image-opacity);
background-image: var(--bg-image);
background-size: cover;
background-position: center;
}
/* other styling */
body {
font-family: system-ui;
font-size: 1.5rem;
}