text-transform

Term side of the Card.
Topic: Text Handling
Unit title: text-transform
Categories: Property
Explanation side of the Card

Explanation: The property that controls the capitalization of text content within an element. It can convert text to uppercase, lowercase or capitalize the first letter of each word, providing a simple way to alter the appearance of text without changing the underlying content.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wronghtml
<button class="btn">
  SAVE CHANGES
</button>
Righthtml
<button class="btn">Save changes</button>
<style>
  .btn {
    text-transform: uppercase;
  }
</style>

Keeping normal case in the markup lets design change in CSS and avoids screen readers reading caps oddly.

Common mistakes

  • capitalize was expected to make sentence case, but it capitalizes the first letter of every word.
  • Some screen readers spell out words typed in all caps in the HTML.

Key points

  • Text is written in normal case in HTML and made uppercase with text-transform, not typed in capitals.
  • Uppercase labels add a little letter-spacing to stay readable.

Interview questions

How do I make sentence case with CSS?

There is no sentence-case value. Lowercase the text and use ::first-letter with text-transform: uppercase on the element.

Does text-transform change the actual text?

No. It only changes how text is displayed; the DOM text stays the same.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy