Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to create texture background using CSS ?
Next article icon

How to use Text as Background using CSS?

Last Updated : 15 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

Table of Content

  • Using Absolute Positioning Inside a Relative Container
  • Using ::after Pseudo-Element
  • Using ::before Pseudo-Element

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 :



Next Article
How to create texture background using CSS ?

C

chaitanyashah707
Improve
Article Tags :
  • CSS
  • Web Technologies
  • CSS-Questions

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>. Syntax border: "borderWidth borderStyle colorName;"Example 1: Adding a border around the text content using CSS. [GFGTABS] HTML <p> The following text has a borde
    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
  • How to bold the text using CSS ?
    In HTML, we use the <b> and <strong> tags to make content bold. However, when it comes to styling text, CSS provides a more versatile way to achieve boldness through the font-weight property. This property allows you to set various boldness levels for your text to mark something importan
    2 min read
  • How to set multiple background images using CSS?
    The multiple background images for an element can be put in the HTML page using CSS. Use CSS background property to add multiple background images for an element in any pattern and use other CSS property to set the height and width of the images. The used background property are listed below: backgr
    2 min read
  • How to make bubble background using HTML5 and CSS3?
    Water bubble background animation can easily be generated by using HTML, CSS JavaScript. By using HTML5 we will design the basic body part of the page and by CSS3 we will make the bubbles in the background, And with the help of JavaScript, it will move over the whole page from bottom to up. Approach
    4 min read
  • How to Set background Image using jQuery css() Method ?
    This article will show you how to set the background image using jQuery. To set the background image, we are using the jQuery css() method. jQuery css() MethodThis method sets/returns one or more style properties for the specified elements. Syntax: Return a CSS property:$(selector).css("propertyname
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences