Image as Text Background using CSS background-clip Property

You can set Image as text background of any HTML element using CSS background-clip property, background-clip limits the background image to the content of element.


background-clip property specifies the limit of background of any html element, The default value of background-clip is border-box.


div {
  background-color: blue;
  background-clip: padding-box;


The HTML code is given below, The image background is set for h1 element.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Image as Text Background</title>
    <link rel="stylesheet" href="style.css">
    <h1>How To Code School</h1>    

CSS Code

Using CSS the element is aligned in center both vertically and horizontally, then the image (bg.jpg) is set as background of h1 element and it is clipped to limit the image to the content, i.e text inside h1 element.

Color of text is set to transparent to make the background image visible.

    padding: 0;
    margin: 0;
    font-family: fantasy;
    font-size: 74px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: #000;
    text-transform: uppercase;
    background-image: url(bg.jpg);
    background-clip: text;
    color: transparent;

Video Tutorial

Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Simple Price Range Slider With HTML CSS and JavaScript Circle With Two Colors using CSS Card With Ribbon using HTML and CSS Simple Loading Screen using HTML and CSS Disable Textarea Resizable Property using CSS Button like Links using CSS Simple Dropdown Menu Using HTML and CSS Background Color Transition using CSS Highlight Required Input Fields using CSS Disable HTML Link using CSS Difference Between Descendant Selector and Child Selector How To Change Color and Size of Hr Tag Using CSS How To Center Align HTML Table Convert Checkbox To Toggle Button Using CSS Drawing Stars using HTML and CSS Button Bounce Effect using CSS Image as Text Background using CSS background-clip Property Vertically Rotate HTML Element using CSS Vertical Align Middle using CSS Text Over Image Hover Effect - Css Hover Simple CSS Button Hover Effect using Before Selector