How to Place Text Blocks Over an Image using CSS? Last Updated : 30 Jul, 2024 Comments Improve Suggest changes Like Article Like Report 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 PositioningUsing CSS background-imageUsing Absolute PositioningIn this approach, we are using absolute positioning which allows us to place an element precisely where we want inside another element. We first make the container element position relative to serve as a reference point. Then we use position absolute on the text element and adjust its top, bottom, left, or right values to position it over the image. Example: The example below uses the absolute positioning property to place text blocks on the image using CSS. HTML <!DOCTYPE html> <html> <head> <style> .container { display: flex; justify-content: center; align-items: center; width: 300px; height: 200px; position: relative; } .image { width: 100%; height: 100%; object-fit: cover; } .text { color: white; text-align: center; position: absolute; top: 2%; left: 2%; right: 2%; background-color: rgba(0, 0, 0, 0.5); padding: 10px; z-index: 1; } </style> </head> <body> <div class="container"> <img class="image" src= "https://media.geeksforgeeks.org/wp-content/uploads/20240513173522/GfgImage.png" alt="Image"> <div class="text"> Welcome to GeeksForGeeks! </div> </div> </body> </html> Output:Using CSS background-imageIn this approach, we are using CSS background-image to place text blocks over an image. Here we set the image as the background of a container element. The text block is then placed inside the container.Example: The example below uses CSS background-image property to place text blocks over an image. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> .container { position: relative; width: 350px; height: 300px; background-image: url( 'https://media.geeksforgeeks.org/wp-content/uploads/20240513173522/GfgImage.png'); background-size: cover; display: flex; justify-content: center; align-items: center; } .text { background-color: rgba(0, 0, 0, 0.5); color: white; padding: 10px 20px; font-size: 18px; } </style> </head> <body> <div class="container"> <div class="text"> This is GeeksForGeeks logo </div> </div> </body> </html> Output:Output Comment More infoAdvertise with us Next Article How to Place Text Blocks Over an Image using CSS? G ghuleyogesh Follow Improve Article Tags : Web Technologies CSS CSS-Questions 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 on Image using HTML and CSS? 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 3 min read How to repeat border image using CSS ? You can repeat border images using the border-image-repeat property in CSS. It is generally used for scaling and tiling the border-image. It is used to match the middle part of the border-image to the size of the border.Syntax:border-image-repeat: stretch|repeat|round|initial|inheritNote: The border 2 min read How to Center an Image using text-align Property in CSS ? Aligning an image horizontally within a container can sometimes be challenging. In this article, we will explore how to center an image using the text-align property in CSS. Understanding the text-align PropertyThe text-align property in CSS is used to specify the horizontal alignment of text within 2 min read How To Put Text Over An Image In Google Docs Placing text over images in Google Docs can make your documents visually appealing and more engaging. This is a useful technique for creating presentations, flyers, or marketing materials. While Google Docs is mainly for text editing, there are ways to overlay text on images with some simple tricks. 6 min read Like