Menu Close

How to change div text using css

change text

In the below example, we will learn how to change div text to another text by using css with the help of pseudo elements, visibility modifier and absolute positioning methods.

Sometimes we need to change a particular text in the dynamic contents, for this no need to open the server side to change this and it may affect that loop contents also. So that, CSS method is very useful and simple way to solve this.

Example:

<!DOCTYPE html>
<html> 
<head>
    <title>How to change div text using css</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style> 
        .text-replace { 
            visibility: hidden; 
            position: relative; 
        } 
        .text-replace:after { 
            visibility: visible; 
            position: absolute; 
            top: 0; 
            left: 0; 
            content: "This text replaces the original text."; 
        } 
    </style> 
</head>
<body>
   <p class="text-replace">Old Text</p>
</body>  
</html> 

Output:

change text with css
Posted in CSS, HTML, Web Technologies

You can also read...