How To Place Text on Image using HTML and CSS? Last Updated : 15 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report To place text on an image using HTML and CSS, you can use different techniques to make the text look good and easy to read. Here, we will explore two approaches for placing text over an image using simple HTML and CSS.1. Using Absolute Positioning This approach uses absolute positioning to place the text directly on top of the image. The container that holds the image is positioned relatively, while the text is positioned absolutely inside it, allowing precise control over the text placement. HTML <!DOCTYPE html> <html lang="en"> <head> <style> .gfg { position: relative; width: 100%; text-align: center; } .text-container { position: absolute; color: rgb(255, 255, 255); left: 50%; top: 50%; transform: translate(-50%, -50%); background-color: rgba(41, 41, 41, 0.8); padding: 0.5rem; text-align: center; font-size: 16px; } </style> </head> <body> <div class="gfg"> <img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png" style="width: 50%; height: 60vh;"> <div class="text-container"> <h3>Sample</h3> <p>Mountains Image with river</p> </div> </div> </body> </html> ExplanationContainer Setup: The .gfg class is set to position: relative so that the .text-container can be positioned absolutely within this container.Text Styling: The .text-container uses position: absolute to overlay the text on the image and is centered using left: 50%, top: 50%, and transform: translate(-50%, -50%) for horizontal and vertical centering.Background and Padding: A semi-transparent background (rgba) is added to the text container for readability, with padding to create space around the text.OutputPlace Text on Image using HTML and CSS2. Using CSS background-image PropertyIn this approach, the image is used as a background for a div, and the text is overlaid within the container. This is useful when you want the image to cover the entire container, and you want to have flexible control over the text overlay. HTML <!DOCTYPE html> <html lang="en"> <head> <style> .container { position: relative; width: 400px; height: 300px; background-image: url("https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"); background-size: cover; background-size: 100% 100%; color: white; text-align: center; line-height: 300px; } .text { background-color: rgba(0, 0, 0, 0.5); font-size: 20px; font-weight: bold; padding: 10px; } </style> </head> <body> <center> <div class="container"> <div class="text">Text on Image : (GeeksforGeeks)</div> </div> </center> </body> </html> ExplanationBackground Setup: .container uses background-image to set the image, with cover to fill the space and center for alignment.Text Styling: The text is styled with a semi-transparent background (rgba) and line-height for vertical centering.Flexibility: This method allows easy control of text and image positioning.OutputUsing CSS background-image Property How to place text on image using HTML and CSS? Comment More infoAdvertise with us Next Article How to Place Text Blocks Over an Image using CSS? R riyakalra59 Follow Improve Article Tags : CSS CSS-Misc HTML-Misc Similar Reads How to Place Text Over an Image using CSS? Place Text Over an Image means overlaying text on top of an image using HTML and CSS. This effect is commonly achieved by placing the image and text inside a container and then using CSS techniques like absolute positioning, z-index, or flexbox to position the text over the image.Below are the appro 2 min read How to Place Text Blocks Over an Image using CSS? Placing text blocks over an image is a common technique used in web design to create visually appealing layouts. Here, we will explore different approaches to achieve this effect using CSS.Below are the approaches to place text blocks over an image using CSS:Table of Content Using Absolute Positioni 2 min read How to Add a Login Form to an Image using HTML and CSS? The login form on an Image is used on many websites. Like hotel websites that contain pictures of the hotels or some organizations that organize special events holding that event picture and login form. In that case, you can design a login or registration form on that picture. This design will make 2 min read How to Add a Login Form to an Image using HTML and CSS? The login form on an Image is used on many websites. Like hotel websites that contain pictures of the hotels or some organizations that organize special events holding that event picture and login form. In that case, you can design a login or registration form on that picture. This design will make 2 min read How to wrap the text around an image using HTML and CSS? Here are three methods to make text around an image using HTML and CSS:1. Using Float PropertyThe float property is the traditional way to position an image and allow text to wrap around it.HTML<html> <head> <style> .image-left { float: left; margin-right: 15px; } </style> 2 min read How to add image refaction using CSS ? This article will show how to add image reflection using CSS. To achieve this task, you can use the -webkit-box-reflect to add the reflection of any HTML element. The box-reflect property is a CSS property that allows you to create a reflection effect for an element. It is primarily used to add a mi 2 min read Like