The text-transform
CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
/* Keyword values */ text-transform: capitalize; text-transform: uppercase; text-transform: lowercase; text-transform: none; text-transform: full-width; /* Global values */ text-transform: inherit; text-transform: initial; text-transform: unset;
The text-transform
property takes into account language-specific case mapping rules, like:
in Turkic languages, like Turkish (tr
), Azerbaijani (az
), Crimean Tatar (crh
), Volga Tatar (tt
), and Bashkir (ba
), there are two kinds of i, with and without the dot, and two case pairings: i
/İ
and ı
/I
.
In German (de
), the ß
becomes SS
in uppercase.
In Dutch (nl
), the ij
digraph becomes IJ
, even with text-transform: capitalize
, which only put the first letter of a word in uppercase.
In Greek (el
), vowels lose their accent when the whole word is in uppercase (ά
/Α
), except for the disjunctive eta (ή
/Ή
). Also, diphthongs with an accent on the first vowel lose the accent and gain a diaeresis on the second vowel (άι
/ΑΪ
).
In Greek (el
), the lowercase sigma character has two forms: σ
and ς
. ς
is used only when sigma terminates a word. When applying text-transform: lowercase
to an uppercase sigma (Σ
), the browser needs to choose the right lowercase form based on context.
ga
), certain prefixed letters remain in lowercase when the base initial is capitalised, so for example text-transform: uppercase
will change ar aon tslí
to AR AON tSLÍ
and not, as one might expect, AR AON TSLÍ
(Firefox only). In some cases, a hyphen is also removed upon uppercasing: an t-uisce
transforms to AN tUISCE
(and the hyphen is correctly reinserted by text-transform: lowercase
)The language is defined by the lang
HTML attribute or the xml:lang
XML attribute.
Support for these specific cases vary from one browser to the other, so check the browser compatibility table.
Initial value | none |
---|---|
Applies to | all elements. It also applies to ::first-letter and ::first-line . |
Inherited | yes |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
capitalize
Is a keyword forcing the first letter of each word to be converted to uppercase. Other characters are unchanged; that is, they retain their original case as written in the element's text. A letter is any Unicode character part of the Letter or Number general categories : it excludes any punctuation marks or symbols at the beginning of the word.
capitalize
to follow language-specific title casing conventions (such as skipping articles in English).capitalize
keyword was under-specified in CSS 1 and CSS 2.1. There were differences between browsers in the way the first letter was calculated (Firefox considered - and _ as letters, but not the others. Both Webkit and Gecko incorrectly considered letter-based symbols like ⓐ
to be real letters. Internet Explorer 9 was the closest to the CSS 2 definition, but with some weird cases). By precisely defining the correct behavior, CSS Text Level 3 cleans this mess up. The capitalize
line in the browser compatibility table contains the version the different engines started to support this now precisely defined behavior.uppercase
lowercase
none
full-width
none | capitalize | uppercase | lowercase | full-width
none
<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p> <p>text-transform: none <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</span></strong> </p>
span { text-transform: none; } strong { float: right; }
This demonstrates no text transformation.
capitalize
(General)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p> <p>text-transform: capitalize <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</span></strong> </p>
span { text-transform: capitalize; } strong { float: right; }
This demonstrates text capitalization.
capitalize
(Punctuation)<p>Initial String <strong>(this) “is” [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</strong> </p> <p>text-transform: capitalize <strong><span>(this) “is” [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!</span></strong> </p>
span { text-transform: capitalize; } strong { float: right; }
This demostrates how initial punctuations of a word are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.
capitalize
(Symbols)<p>Initial String <strong>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</strong> </p> <p>text-transform: capitalize <strong><span>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</span></strong> </p>
span { text-transform: capitalize; } strong { float: right; }
This demonstrates how initial symbols are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.
capitalize
(Dutch ij digraph)<p>Initial String <strong lang="nl">The Dutch word: "ijsland" starts with a digraph.</strong> </p> <p>text-transform: capitalize <strong><span lang="nl">The Dutch word: "ijsland" starts with a digraph.</span></strong> </p>
span { text-transform: capitalize; } strong { float: right; }
This demonstrates how the Dutch ij digraph must be handled like one single letter.
uppercase
(General)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p> <p>text-transform: uppercase <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</span></strong> </p>
span { text-transform: uppercase; } strong { float: right; }
This demonstrates transforming the text to uppercase.
uppercase
(Greek Vowels)<p>Initial String <strong>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</strong> </p> <p>text-transform: uppercase <strong><span>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"</span></strong> </p>
span { text-transform: uppercase; } strong { float: right; }
This demonstrates how Greek vowels except disjunctive eta should have no accent, and the accent on the first vowel of a vowel pair becomes a diaeresis on the second vowel.
lowercase
(General)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p> <p>text-transform: lowercase <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</span></strong> </p>
span { text-transform: lowercase; } strong { float: right; }
This demonstrates transforming the text to lowercase.
lowercase
(Greek Σ)<p>Initial String <strong>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</strong> </p> <p>text-transform: lowercase <strong><span>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.</span></strong> </p>
span { text-transform: lowercase; } strong { float: right; }
This demonstrates how the Greek character sigma (Σ
) is transformed into the regular lowercase sigma (σ
) or the word-final variant (ς
), according the context.
full-width
(General)<p>Initial String <strong>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</strong> </p> <p>text-transform: full-width <strong><span>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</span></strong> </p>
span { text-transform: full-width; } strong { width: 100%; float: right; }
Some characters exists in two formats, normal width and a full-width, with different Unicode code points. The full-width version is used to mix them smoothly with Asian ideographic characters.
Specification | Status | Comment |
---|---|---|
CSS Text Level 4 The definition of 'text-transform' in that specification. | Working Draft | From CSS Text Module Level 3 The definition of 'text-transform' in that specification., adds the full-size-kana keyword and allows the full-width keyword to be used together with another keyword. |
CSS Text Module Level 3 The definition of 'text-transform' in that specification. | Working Draft | From CSS Level 2 (Revision 1) The definition of 'text-transform' in that specification., extends letters to any Unicode character in the Number or Letter general category. Modifies the behavior of capitalize to apply to the first letter of the word, ignoring initial punctuations or symbols. Adds the full-width keyword to mix smoothly ideographic characters and alphabetical characters. |
CSS Level 2 (Revision 1) The definition of 'text-transform' in that specification. | Recommendation | From CSS Level 1 The definition of 'text-transform' in that specification., extends letters to non-latin bi-cameral scripts |
CSS Level 1 The definition of 'text-transform' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 11 | Yes | 1 | 4 | 72 | 13 |
capitalize as defined by CSS level 3 |
? | ? | 14 | ? | ? | ? |
full-width |
No | ? | 19 | No | No | No |
Dutch IJ digraph |
No | ? | 14 | No | No | No |
Greek accented letters | 30 | ? | 15 | No | No | No |
Σ → σ or word-final ς
|
30 | ? | 14 | No | No | 6 |
i → İ and ı → I
|
No | ? | 14 | ? | ? | No |
ß → SS
|
? | ? | 1 | ? | ? | ? |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | 11 | ? | Yes | 4 | 6 | ? | 13 |
capitalize as defined by CSS level 3 |
? | ? | ? | 14 | ? | ? | ? |
full-width |
No | ? | ? | 19 | No | No | No |
Dutch IJ digraph |
No | ? | ? | 14 | No | No | No |
Greek accented letters | No | ? | ? | No | No | No | No |
Σ → σ or word-final ς
|
No | ? | ? | 14 | No | No | No |
i → İ and ı → I
|
No | ? | ? | 14 | ? | ? | No |
ß → SS
|
? | ? | ? | 4 | ? | ? | ? |
1. The text-transform
property does not work for ::first-line
pseudo-elements (nor for the one-colon syntax). See Chromium bug 129669.
2. Since Opera 15, the text-transform
property does not work for ::first-line
pseudo-elements (nor for the one-colon syntax). See Chromium bug 129669.
3. The text-transform
property does not work for ::first-line
pseudo-elements (also not for the old one-colon syntax). See WebKit bug 3409.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform