Style textTransform attribute

Definition and Usage

textTransform Attribute sets or returns the case of the text.

This attribute is used to modify text to uppercase, lowercase, or capitalize the first letter.

See also:

CSS Tutorial:CSS 文本

CSS Reference Manual:text-transform attribute

Example

Example 1

Convert the first letter of each word in the <p> element to uppercase:

document.getElementById("myP").style.textTransform = "capitalize";

Try It Yourself

Example 2

Convert all characters in the <p> element to uppercase:

document.getElementById("myP").style.textTransform = "uppercase";

Try It Yourself

Example 3

Return the text transformation of the <p> element:

alert(document.getElementById("myP").style.textTransform);

Try It Yourself

Syntax

Return textTransform attribute:

object.style.textTransform

Set textTransform attribute:

object.style.textTransform = "none|capitalize|uppercase|lowercase|initial|inherit"

Attribute Value

Value Description
none No characters are converted. Default.
capitalize The first character of each word is converted to uppercase.
uppercase All characters are converted to uppercase.
lowercase All characters are converted to lowercase.
initial Set this attribute to its default value. See initial
inherit This attribute is inherited from its parent element. See inherit

Technical Details

Default Value: None
Return Value: 字符串,表示元素中文本的转换。
CSS 版本: CSS1

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持