How To Add Text Over An Image Using HTML and CSS?


First of all create a <div class="box">...</div> in the HTML document.
Then add this HTML code between <div class="box">...</div>.
<div class="box">
    <img src="image.png" alt="image">
    <div class="center">Center Text</div>
    <div class="top-left">Top-Left Text</div>
    <div class="top-right">Top-Right Text</div>
    <div class="bottom-right">Bottom-Right Text</div>
    <div class="bottom-left">Bottom-Left Text</div>
</div>


Add this CSS code.
.box {
   position: relative;
   color: rgb(255,255,255);
 }
.center{
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%,-50%);
}
.top-left{
   position: absolute;
   top: 10px;
   left: 10px;
}
.top-right{
   position: absolute;
   top: 10px;
   right: 10px;
}
.bottom-right{
   position: absolute;
   bottom: 10px;
   right: 10px;
}
.bottom-left{
   position: absolute;
   bottom: 10px;
   left: 10px;
}


Output

image
Center Text
Top-Left Text
Top-Right Text
Bottom-Right Text
Bottom-Left Text



Trending Posts

What Are The Use of Function Keys F1 to F12 on The Keyboard?

Create Light & Dark Theme Toggle Using HTML, CSS & JavaScript

How To Create A Magic 8 Ball Using HTML, CSS, and JavaScript?

Strengthen Your IT Infrastructure: Scalable Strategies for a Future-Proof Business

Bridging the Language Divide: How Modern IT Professionals Can Make Their Work Make Sense

🚀 Build a QR Code Generator Using HTML, CSS & JavaScript

The Rise of Agentic AI: How Autonomous Coding Agents Are Replacing Junior Devs

Build a Simple Calculator Using HTML, CSS, and JavaScript 💻

AI vs. Human Hackers: Who Wins the Cybersecurity Arms Race in 2025?

The Secret Formula to Grow as a Programmer