How to use Text as Background using CSS?
Last Updated :
15 Oct, 2024
Using text as a background in CSS means creating a visual effect where large text is placed behind content, often appearing as a decorative or watermark-like element. This effect can be achieved by positioning, opacity adjustments, and layering techniques with CSS.
Here we have some common methods to make Text as Background:
1. Using Absolute Positioning Inside a Relative Container
Using absolute positioning inside a relative container involves setting the parent container to position: relative and the child element to position: absolute. This allows the child to be precisely positioned within the container, enabling creative layout control and background effects.
Example: Here we CSS to position and rotate background text behind content. The .containerbackground element is rotated and placed behind the main text using absolute positioning.
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Using text as background with CSS
</title>
<style>
.container {
position: relative;
}
.containerbackground {
margin: 3rem;
position: absolute;
top: 0;
left: 0;
bottom: 0;
z-index: -1;
transform: rotate(300deg);
-webkit-transform: rotate(300deg);
color: #c6afaf;
}
</style>
</head>
<body>
<div class="container">
<div class="containerbackground">
Background Text
</div>
<p>Foreground text</p>
<p>Welcome to GeeksforGeeks</p>
<p>Start Learning</p>
</div>
</body>
</html>
Output:

2. Using ::after Pseudo-Element
The ::after pseudo-element allows you to insert content after an element. By setting its content property and using position and z-index, you can create text or other elements that appear as a background behind the main content.
Example: Here the :after pseudo-element to display rotated background text behind content. The background text appears behind the paragraphs
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Using text as background with CSS
</title>
<style>
.bgtext {
position: relative;
}
.bgtext:after {
margin: 3rem;
content: "Background text";
position: absolute;
transform: rotate(300deg);
-webkit-transform: rotate(300deg);
color: rgb(187, 182, 182);
top: 0;
left: 0;
z-index: -1;
}
</style>
</head>
<body>
<div class="bgtext">
<p>Foreground text</p>
<p>Welcome to GeeksforGeeks</p>
<p>Start Learning</p>
</div>
</body>
</html>
Output:

3. Using ::before Pseudo-Element
The ::before pseudo-element inserts content before an element’s actual content. By setting the content property and using position and z-index, you can style this content to appear behind the main element, creating a background-like effect for design purposes.
Example: Here the :before pseudo-element to position and rotate background text behind the content. The background text appears rotated and styled using absolute positioning and a light color.
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Using text as background with CSS
</title>
<style>
.bgtext {
position: relative;
}
.bgtext:before {
margin: 3rem;
content: "Background text";
position: absolute;
transform: rotate(300deg);
-webkit-transform: rotate(300deg);
color: rgb(187, 182, 182);
top: 0;
left: 0;
z-index: -1;
}
</style>
</head>
<body>
<div class="bgtext">
<p>Foreground text</p>
<p>Welcome to GeeksforGeeks</p>
<p>Start Learning</p>
</div>
</body>
</html>
Output :
Similar Reads
How to create texture background using CSS ? Introduction: We can use CSS property to texture the background of the web page by using an image editor to cut out a portion of the background. Apply CSS background-repeat property to make the small image fill the area where it is used. CSS provides many styling properties of the background includi
3 min read
How to Add Border Around Text using CSS? The CSS border property is used to add a border around text by wrapping the text in an HTML element like <span> or <p>. Syntaxborder: "borderWidth borderStyle colorName;"Example 1: Adding a border around the text content using CSS.HTML<p> The following text has a border <span st
1 min read
How to blur background image using CSS ? CSS (Cascading Style Sheets) is a language used to describe the appearance and formatting of a document written in HTML. In this article, we will learn how to blur background images using CSS, along with basic implementation examples. Blurring Background Images with CSSTo blur a background image usi
3 min read
How to give text or an image transparent background using CSS ? In this article, we will know to make the text or image a transparent background using the CSS & will see its implementation through the example. The opacity property is used to set image or text transparent using CSS. The opacity attribute is used to adjust the transparency of text or pictures.
2 min read
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. To add an image in the text background using HTML and CSS, create a container element (e.g., a `<div>`), set its background to the desired imag
2 min read
How to Add filter to the background image using CSS? Adding filters to background images using CSS allows you to apply visual effects like blur, grayscale, brightness adjustment, and more without modifying the actual image file. CSS provides a set of filter functions that can be applied to elements with background images. This approach enhances design
3 min read