HTML | DOM Style textTransform Property

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"

Property Values:

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

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>                    

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>                    

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>            

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>                    

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>                    

    chevron_right

    
    

    Output:

    • Before clicking the button:
      initial-before
    • After clicking the button:
      initial-after
  • inherit: It inherits the property from its parent element.

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>                    

    chevron_right

    
    

    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
  • Internet Explorer
  • Firefox
  • Opera
  • Apple Safari


My Personal Notes arrow_drop_up

Technical Writer Lets have an update

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.