Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

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

  • Difficulty Level : Medium
  • Last Updated : 11 May, 2020

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.

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




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

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.




<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>

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




<!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>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :