How to create an image with a transparent background text using CSS?

CSSWeb DevelopmentFront End Technology

Following is the code to create an image with transparent background text using CSS −


 Live Demo

<!DOCTYPE html>
<meta name="viewport" imageContent="width=device-width, initial-scale=1">
* {
   box-sizing: border-box;
body {
   font-family: Arial;
   font-size: 17px;
.imageContainer {
   display: inline-block;
   position: relative;
.imageContainer .imageContent {
   position: absolute;
   bottom: 0;
   background: rgba(29, 6, 43, 0.5); /* Black background with 0.5 opacity */
   color: #f1f1f1;
   width: 100%;
   padding: 20px;
<h2>Image with Transparent Text</h2>
<div class="imageContainer">
<img src="">
<div class="imageContent">
<h3>A beautiful scenary showing fence, barbed wires and grass</h3>


The above code will produce the following output −

Updated on 06-Apr-2020 13:02:11