How to put text on an image using HTML and CSS?

Views: 448
Comments: 0
Like/Unlike: 0
Posted On: 23-Jan-2023 23:08 

Share:   fb twitter linkedin
60 Points
6 Posts

We are going to achieve above result by using html and css.

CSS position property is used to set the position of text over an image. This can be  acheived by putting img tag and div 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.

<!DOCTYPE html>
        .gfg {
            margin: 3%;
            position: relative;
        .first-txt {
            position: absolute;
            top: -15px;
            left: 200px;
            color: white;
        .second-txt {
            position: absolute;
            bottom: -10px;
            left: 200px;
          color: red;
    <div class="gfg">
        <img style="width:600px" src="">
        <h3 class="first-txt">
            Put me top on an image
        <h3 class="second-txt">
            Put me bottom on an image
 Log In to Chat