<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<div>Some text heere just text and nothing more</div>
</body>
<style>
div {
background: rgba(0, 0, 0, 0.5);
color: white;
}
</style>
</html>
Here I used rgba to set background color instead of just the name so the last value specifies alpha!
And incase of image use something like this :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<div>Some text heere just text and nothing more</div>
</body>
<style>
div {
width: 200px;
height: 200px;
display: block;
position: relative;
}
div::after {
content: "";
background: url(https://picsum.photos/200/300);
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
</style>
</html>