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 >
function setTransform() {
elem = document.querySelector('.content');
elem.style.textTransform = 'capitalize';
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking the button:

- After clicking the button:

- 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 >
function setTransform() {
elem = document.querySelector('.content');
elem.style.textTransform = 'uppercase';
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking the button:

- After clicking the button:

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

- After clicking the button:

- 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 >
function setTransform() {
elem = document.querySelector('.content');
elem.style.textTransform = 'none';
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking the button:

- After clicking the button:

- 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 >
function setTransform() {
elem = document.querySelector('.content');
elem.style.textTransform = 'initial';
}
</ script >
</ body >
</ html >
|
Output:
- Before clicking the button:

- After clicking the button:

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

- After clicking the button:

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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Jun, 2022
Like Article
Save Article