Skip to content
Related Articles

Related Articles

HTML | DOM Style textTransform Property

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 07 Jun, 2022

The Style textTransform property in HTML DOM is used to set or return the capitalization of text. It can be used to make the required text uppercase, lowercase or capitalize the first character of each word. 

Syntax:

  • It returns the textTransform property.
object.style.textTransform
  • It is used to set the textTransform property.
object.style.textTransform = "capitalize|uppercase|lowercase|
none|initial|inherit"

Return Values: It returns a string value, that represents the transformation of the text in the element

Property Values:

  • capitalize: This value capitalizes the first letter of every word of the text. 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textTransform Property
    </title>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used
        to capitalize, uppercase or lowercase
        the text.
    </p>
     
    <p class="content">
        GeeksforGeeks is a computer science portal.
    </p>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <!-- Script to capitalize first character
        of each word -->
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'capitalize';
        }
    </script>
</body>
 
</html>                   

Output:

  • Before clicking the button:

 capitalize-before

  • After clicking the button:

 capitalize-after

  • uppercase: This value transforms every letter of the text to uppercase. 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textTransform Property
    </title>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used
        to capitalize, uppercase or lowercase
        the text.
    </p>
     
    <p class="content">
        GeeksforGeeks is a computer science portal.
    </p>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <!-- Script to capitalize each character -->
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'uppercase';
        }
    </script>
</body>
 
</html>                   

Output:

  • Before clicking the button:

 uppercase-before

  • After clicking the button:

 uppercase-after

  • lowercase: This value transforms every letter of the text to lowercase. 

Example: 

html




<!DOCTYPE html>
<html>
      
<head>
    <title>
        DOM Style textTransform Property
    </title>
</head>
  
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
      
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used to
        capitalize, uppercase or lowercase the text.
    </p>
     
    <p class="content">
        GeeksforGeeks Is A ComPuTer sCiEnce PortAL.
    </p>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'lowercase';
        }
    </script>
</body>
 
</html>           

Output:

  • Before clicking the button:

lowercase-before

  • After clicking the button:

 lowercase-after

  • none: It is the default value that specifies no transformation takes place. 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textTransform Property
    </title>
     
    <style>
        .content {
            width: 500px;
  
            /* Set text-transform before to
            observe effect of 'none' */
            text-transform: capitalize;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used
        to capitalize, uppercase or lowercase
        the text.
    </p>
     
    <p class="content">
        GeeksforGeeks is a computer science portal.
    </p>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <!-- Script to convert lower case
        of each word -->
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'none';
        }
    </script>
</body>
 
</html>                   

Output:

  • Before clicking the button:

 none-before

  • After clicking the button:

 none-after

  • initial: This is used to set this property to its default value. 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textTransform Property
    </title>
     
    <style>
        .content {
            width: 500px;
  
            /* Set text-transform before to
            observe effect of 'none' */
            text-transform: capitalize;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used
        to capitalize, uppercase or lowercase
        the text.
    </p>
     
    <p class="content">
        GeeksforGeeks is a computer science portal.
    </p>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <!-- Script to change lower case
        of each word -->
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'initial';
        }
    </script>
</body>
 
</html>                   

Output:

  • Before clicking the button:

 initial-before

  • After clicking the button:

 initial-after

  • inherit: It inherits the property from its parent element. 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        DOM Style textTransform Property
    </title>
     
    <style>
        #parent {
             
            /* Set text-transform of parent to
            observe effect of 'inherit' */
            text-transform: uppercase;
        }
        .content {
            width: 500px;
 
            /* Set text-transform to initial to prevent
            auto inheritance of parent */
            text-transform: initial;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
     
    <b>DOM Style textTransform Property</b>
     
    <p>
        The textTransform property can be used to
        capitalize, uppercase or lowercase the text.
    </p>
     
    <div id="parent">
        <p class="content">
            GeeksforGeeks is a computer science portal.
        </p>
    </div>
     
    <button onclick="setTransform()">
        Change textTransform
    </button>
     
    <script>
        function setTransform() {
            elem = document.querySelector('.content');
            elem.style.textTransform = 'inherit';
        }
    </script>
</body>
 
</html>                   

Output:

  • Before clicking the button: 

inherit-before

  • After clicking the button:

 inherit-after

Supported Browsers: The browser supported by DOM Style textTransform property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 4 and above
  • Firefox 1 and above
  • Opera 7 and above
  • Apple Safari 1 and above

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!