How to Add Image in Text Background using HTML and CSS ?

In this article, we will use HTML and CSS to set the image in the text background. To set the image in the text background, some CSS property is used.

HTML Code: HTML code is used to create a basic structure of the body. In the following code, we will use paragraph tag to write text content.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to Add Image in Text Background
        using HTML and CSS ?
    </title>
</head>
  
<body>
    <p>GeeksforGeeks</p>
</body>
  
</html>

chevron_right


CSS Code: The CSS property is used to set the image as background in the text. The background-image property is used to set an image as background. The -webkit-text-fill-color property is used to give the text a transparent color, the background image will show through the text, thus completing the clipping effect.

filter_none

edit
close

play_arrow

link
brightness_4
code

<style>
    p {
        background-image: url(demo.jpg);
        background-repeat: repeat;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-top: 200px;
        font-size: 120px;
        text-align: center;
        font-weight: bold;
        text-transform: uppercase;
        font-family: 'Steelfish Rg', 'helvetica neue',
                    helvetica, arial, sans-serif;
        font-weight: 800;
        -webkit-font-smoothing: antialiased;
    }
</style>

chevron_right


Complete Code: In this section, we will combine the above two sections to add an image as text background.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to Add Image in Text Background
        using HTML and CSS ?
    </title>
      
    <style>
        p {
            background-image: url(demo.jpg);
            background-repeat: repeat;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-top: 200px;
            font-size: 120px;
            text-align: center;
            font-weight: bold;
            text-transform: uppercase;
            font-family: 'Steelfish Rg', 'helvetica neue',
                     helvetica, arial, sans-serif;
            font-weight: 800;
            -webkit-font-smoothing: antialiased;
        }
    </style>
</head>
  
<body>
    <p>GeeksforGeeks</p>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.