CSS position property is used to set the position of text over an image. This can be done by enclosing the image and text in an HTML “div”. Then make the position of div “relative” and that of text “absolute”. The absolute elements are positioned relative to their parent (div). The top, right, bottom, and left properties of these elements specify their location from the parent.
Example 1:
<!DOCTYPE html> <html> <head> <style> .gfg { margin: 3%; position: relative; } .first-txt { position: absolute; top: 17px; left: 50px; } .second-txt { position: absolute; bottom: 20px; left: 10px; } </style> </head> <body> <div class="gfg"> <img src="gfg.png"> <h3 class="first-txt"> GeeksforGeeks </h3> <h3 class="second-txt"> A computer science portal </h3> </div> </body> </html> |
Output:

Example 2:
<!DOCTYPE html> <html> <head> <style> .gfg { margin: 3%; position: relative; } .first-txt { position: absolute; top: 17px; left: 20px; } .second-txt { position: absolute; top: 17px; left: 150px; } </style> </head> <body> <div class="gfg"> <img src="gfg.png"> <h3 class="first-txt">Left</h3> <h3 class="second-txt">Right</h3> </div> </body> </html> |
Output:

Recommended Posts:
- How to place text in an image at any desired position ?
- How to Add Image in Text Background using HTML and CSS ?
- How to wrap the text around an image using HTML and CSS ?
- How to place table text into center using Bootstrap?
- How to place the image above the slider in mobile view in bootstrap?
- How to select all text in HTML text input when clicked using JavaScript?
- Text Animation with changing the color of the text using HTML & CSS
- How to Vertically Align Text Next to an Image using CSS ?
- Convert an image into grayscale image using HTML/CSS
- How to give text or an image transparent background using CSS?
- Image Replacement in Bootstrap using text-hide Class
- How to change the text and image by just clicking a button in JavaScript ?
- How to create long shadow of text without using text-shadow in HTML and CSS ?
- HTML | Text Formatting
- HTML | DOM Input Text Object
- HTML | DOM Title text Property
- Create a 3D Text Effect using HTML and CSS
- How to Skew Text on Hover using HTML and CSS?
- HTML | <input type="text">
- HTML | DOM Option text Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


