Tillitsdone
down Scroll to discover

CSS text-transform Mastering Text Capitalization

Discover CSS text-transform for controlling text capitalization.

Options include uppercase, lowercase, capitalize, full-width, full-size-kana, and math-auto.
thumbnail

Introduction

The text-transform property in CSS is a powerful tool that lets you control text capitalization on your web pages. It helps ensure consistent and visually appealing text formatting, making your content easier to read and more professional.

Understanding and using text-transform can significantly enhance your web development skills. Whether you’re working on a professional website, a blog, or an e-commerce platform, this property can help you maintain a polished look.

In this guide, we’ll explore the various aspects of text-transform, including its syntax, property values, and practical examples. We’ll also cover language-specific case mapping rules, accessibility considerations, and browser compatibility. By the end, you’ll have a comprehensive understanding of how to effectively use text-transform to elevate your web projects.

Specification

The text-transform property is defined in the CSS Text Module Level 3 specification. This module outlines the rules and behaviors for text transformation in web design. The specification ensures that the property behaves consistently across different browsers and languages.

Understanding the specification is essential for web developers aiming to create accessible and visually appealing web pages. By adhering to the CSS Text Module Level 3 guidelines, you can ensure that your text transformations are both effective and standards-compliant.

Language-Specific Case Mapping

The text-transform property in CSS handles language-specific case mapping rules, ensuring that text transformations are accurate and culturally appropriate. Here are some key examples:

Turkic Languages

In Turkic languages like Turkish, Azerbaijani, Crimean Tatar, Volga Tatar, and Bashkir, there are specific rules for i/İ and ı/I. Proper case mapping ensures these characters are transformed correctly.

German

In German, the character ß becomes SS in uppercase. This rule is essential for maintaining the correct spelling and readability of German text.

Dutch

In Dutch, the ij digraph becomes IJ, even with text-transform: capitalize, which only puts the first letter of a word in uppercase.

Greek

In Greek, vowels lose their accent when the whole word is in uppercase, except for the disjunctive eta (ή/Ή). Diphthongs with an accent on the first vowel lose the accent and gain a diaeresis on the second vowel (άι/ΑΪ). Additionally, the lowercase sigma character has two forms: σ and ς. When applying text-transform: lowercase to an uppercase sigma (Σ), the browser needs to choose the correct lowercase form based on context.

Irish

In Irish, certain prefixed letters remain in lowercase when the base initial is capitalized. For example, text-transform: uppercase will change ar aon tslí to AR AON tSLÍ, not AR AON TSLÍ. In some cases, a hyphen is also removed upon uppercasing: an t-uisce transforms to AN tUISCE.

Adhering to these language-specific case mapping rules ensures that text transformations are accurate and respect the linguistic nuances of different languages. This is particularly important for creating multilingual websites that are accessible and understandable to a global audience.

Syntax

The text-transform property in CSS is straightforward to use. Its syntax is designed to be intuitive and easy to implement. The property allows you to specify how text should be capitalized within an HTML element.

Basic Syntax

text-transform: none | capitalize | uppercase | lowercase |
full-width | full-size-kana | math-auto |
inherit | initial | revert | revert-layer | unset;

Keyword Values

  • none: This is the default value. It means no transformation is applied, and the text remains as it is written.
  • capitalize: This value transforms the first letter of each word to uppercase while leaving the rest of the letters unchanged.
  • uppercase: This value converts all characters in the text to uppercase.
  • lowercase: This value converts all characters in the text to lowercase.
  • full-width: This value forces characters to be displayed in a full-width format, useful for aligning text with East Asian scripts like Chinese or Japanese.
  • full-size-kana: This value is generally used for <ruby> annotation text and converts small Kana characters to their equivalent full-size Kana to improve legibility at small font sizes.
  • math-auto: This value automatically renders text in mathematical italic where appropriate, transforming Latin and Greek letters and specific math-related symbols to italic mathematical symbols.

Global Values

  • inherit: Inherits the value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Rolls back the value to the browser’s default.
  • revert-layer: Rolls back the value to the default of the cascade layer.
  • unset: Resets the property to its natural value, which means it behaves like inherit if the property is inherited or initial if it is not.

Example

Here’s an example of how to use the text-transform property in CSS:

p {
text-transform: uppercase;
}

In this example, all paragraph (<p>) text will be transformed to uppercase.

Understanding the syntax and values of the text-transform property is essential for web developers to effectively control text capitalization and ensure consistent formatting across their web pages. By using the appropriate keyword values, developers can enhance the readability and visual appeal of their content.

Property Values

The text-transform property in CSS supports several values that allow you to control the capitalization of text in various ways. Each value serves a specific purpose and can be used to achieve different text effects.

none

  • Description: This is the default value. It means no transformation is applied, and the text remains as it is written.
  • Usage: Use this value when you want the text to appear exactly as it is in the HTML, without any capitalization changes.
p {
text-transform: none;
}

capitalize

  • Description: This value transforms the first letter of each word to uppercase while leaving the rest of the letters unchanged.
  • Usage: Use this value to capitalize the first letter of each word, which is useful for titles and headings.
p {
text-transform: capitalize;
}

uppercase

  • Description: This value converts all characters in the text to uppercase.
  • Usage: Use this value to create a strong visual emphasis, such as in headings or important information.
p {
text-transform: uppercase;
}

lowercase

  • Description: This value converts all characters in the text to lowercase.
  • Usage: Use this value to create a more casual or subdued appearance, such as in body text or notes.
p {
text-transform: lowercase;
}

full-width

  • Description: This value forces characters to be displayed in a full-width format, which is useful for aligning text with East Asian scripts like Chinese or Japanese.
  • Usage: Use this value when you need to align text neatly with ideographic characters.
p {
text-transform: full-width;
}

full-size-kana

  • Description: This value is generally used for <ruby> annotation text and converts small Kana characters to their equivalent full-size Kana to improve legibility at small font sizes.
  • Usage: Use this value to enhance the readability of ruby annotations in Japanese text.
p {
text-transform: full-size-kana;
}

math-auto

  • Description: This value automatically renders text in mathematical italic where appropriate, transforming Latin and Greek letters and specific math-related symbols to italic mathematical symbols.
  • Usage: Use this value to format mathematical expressions correctly, especially when working with MathML.
p {
text-transform: math-auto;
}

Global Values

These values apply to all CSS properties and provide additional control over inheritance and default behaviors.

inherit

  • Description: Inherits the value from the parent element.
  • Usage: Use this value when you want the text transformation to be the same as the parent element.
p {
text-transform: inherit;
}

initial

  • Description: Sets the property to its default value.
  • Usage: Use this value to reset the text transformation to its default state.
p {
text-transform: initial;
}

revert

  • Description: Rolls back the value to the browser’s default.
  • Usage: Use this value to revert to the browser’s default styling for the text transformation.
p {
text-transform: revert;
}

revert-layer

  • Description: Rolls back the value to the default of the cascade layer.
  • Usage: Use this value to revert to the default styling of the cascade layer for the text transformation.
p {
text-transform: revert-layer;
}

unset

  • Description: Resets the property to its natural value, which means it behaves like inherit if the property is inherited or initial if it is not.
  • Usage: Use this value to reset the text transformation to its natural state.
p {
text-transform: unset;
}

Summary

The text-transform property offers a range of values that allow you to control the capitalization of text effectively. By understanding and using these values, you can enhance the visual appeal and readability of your web content. Whether you need to capitalize headings, convert text to uppercase, or improve the legibility of mathematical expressions, the text-transform property provides the flexibility to achieve your desired text effects.

Examples

Understanding the text-transform property in CSS becomes even more practical when you see it in action. Here are several examples that demonstrate how to use the various values of text-transform to achieve different text effects.

Example Using none

This example shows how to use text-transform: none; to display text in its original form without any capitalization changes.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: none;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: none:</h2>
<p class="example">Website Example</p>
<p class="example">
It is a computer science portal for geeks.
</p>
</body>
</html>

Example Using capitalize

This example demonstrates how to use text-transform: capitalize; to transform the first letter of each word to uppercase.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: capitalize;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: capitalize:</h2>
<p class="example">Website Example</p>
<p class="example">
It is a computer science portal for geeks.
</p>
</body>
</html>

Example Using uppercase

This example shows how to use text-transform: uppercase; to convert all characters in the text to uppercase.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: uppercase;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: uppercase:</h2>
<p class="example">Website Example</p>
<p class="example">
It is a computer science portal for geeks.
</p>
</body>
</html>

Example Using lowercase

This example demonstrates how to use text-transform: lowercase; to convert all characters in the text to lowercase.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: lowercase;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: lowercase:</h2>
<p class="example">Website Example</p>
<p class="example">
It is a computer science portal for geeks.
</p>
</body>
</html>

Example Using full-width

This example shows how to use text-transform: full-width; to force characters to be displayed in a full-width format.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: full-width;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: full-width:</h2>
<p class="example">0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</p>
</body>
</html>

Example Using full-size-kana

This example demonstrates how to use text-transform: full-size-kana; to convert small Kana characters to their equivalent full-size Kana, which is useful for improving legibility in Japanese text.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
p.example {
text-transform: full-size-kana;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: full-size-kana:</h2>
<p class="example">ァィゥェ ォヵㇰヶ ㇱㇲッㇳ ㇴㇵㇶㇷ ㇸㇹㇺャ ュョㇻㇼ ㇽㇾㇿヮ</p>
</body>
</html>

Example Using math-auto

This example shows how to use text-transform: math-auto; to automatically render text in mathematical italic where appropriate.

<!DOCTYPE html>
<html>
<head>
<title>CSS text-transform Property</title>
<style>
h1 {
color: green;
}
.math-id {
text-transform: math-auto;
}
</style>
</head>
<body>
<h1>Website Example</h1>
<h2>text-transform: math-auto:</h2>
<div>
(<span class="math-id">sin</span>&#8198;<span class="math-id">x</span>)<sup>2</sup>
+ (<span class="math-id">cos</span>&#8198;<span class="math-id">x</span>)<sup>2</sup>
= 1
</div>
</body>
</html>

Summary

These examples showcase how to use the text-transform property to achieve various text effects. By understanding and applying these values, you can enhance the visual appeal and readability of your web content. Whether you need to capitalize headings, convert text to uppercase, or improve the legibility of mathematical expressions, the text-transform property provides the flexibility to achieve your desired text effects.

Accessibility

Ensuring that your web content is accessible to all users, including those with disabilities, is crucial for creating an inclusive web experience. The text-transform property in CSS can impact the readability of your text, especially for users with cognitive concerns such as dyslexia. Here are some key considerations to keep in mind when using text-transform to ensure your content remains accessible:

Large Sections of Uppercase Text

Using the text-transform: uppercase; property extensively can make text difficult to read for many users, including those with dyslexia. Uppercase text can be more challenging to scan and understand, as it lacks the visual cues provided by lowercase letters. To maintain a readable and accessible design, consider using uppercase text sparingly and only for emphasis or headings.

Examples of Accessible Text Transformations

Avoiding All Uppercase Text

Instead of transforming large sections of text to uppercase, use a combination of uppercase and lowercase letters to improve readability. For example:

<!DOCTYPE html>
<html>
<head>
<title>Accessible Text Transformations</title>
<style>
h1 {
text-transform: uppercase;
}
p {
text-transform: none;
}
</style>
</head>
<body>
<h1>Important Headline</h1>
<p>This paragraph is written in a mix of uppercase and lowercase letters to improve readability.</p>
</body>
</html>

Using Capitalize for Headings

For headings and titles, consider using text-transform: capitalize; to maintain a professional and readable format:

<!DOCTYPE html>
<html>
<head>
<title>Accessible Text Transformations</title>
<style>
h2 {
text-transform: capitalize;
}
</style>
</head>
<body>
<h2>an example of a capitalized heading</h2>
<p>This paragraph is written in a mix of uppercase and lowercase letters to improve readability.</p>
</body>
</html>

Best Practices for Accessible Text Transformations

  1. Limit Uppercase Text: Use uppercase text sparingly and only for emphasis or headings. Avoid transforming large blocks of text to uppercase, as it can hinder readability.
  2. Consider Mixed Case: Use a mix of uppercase and lowercase letters for body text to improve readability and comprehension.
  3. Use Capitalize for Headings: Apply text-transform: capitalize; to headings and titles to maintain a professional and accessible format.
  4. Test with Users: Conduct user testing with individuals who have cognitive concerns to ensure that your text transformations are accessible and easy to read.

Resources for Accessibility

For more information on web accessibility and how to create accessible content, consider the following resources:

By following these guidelines and best practices, you can ensure that your use of the text-transform property enhances the accessibility and readability of your web content for all users. Creating an inclusive and accessible web experience is essential for reaching a broader audience and providing a positive user experience.

Formal Definition

The text-transform property in CSS is formally defined to control the capitalization of text within an HTML element. It affects how text is displayed by transforming its case according to specified rules. This property is essential for ensuring consistent and visually appealing text formatting, which can greatly improve readability and overall design.

Initial Value

  • Initial Value: none

Applies To

  • Applies To: All elements, including ::first-letter and ::first-line pseudo-elements.

Inherited

  • Inherited: Yes

Computed Value

  • Computed Value: As specified

Animation Type

  • Animation Type: Discrete

Formal Syntax

The formal syntax for the text-transform property is defined as follows:

text-transform =
none |
[ capitalize | uppercase | lowercase ] |
full-width |
full-size-kana |
math-auto

Keyword Values

  • none: No transformation is applied, and the text remains as it is written.
  • capitalize: Transforms the first letter of each word to uppercase while leaving the rest of the letters unchanged.
  • uppercase: Converts all characters in the text to uppercase.
  • lowercase: Converts all characters in the text to lowercase.
  • full-width: Forces characters to be displayed in a full-width format, useful for aligning text with East Asian scripts.
  • full-size-kana: Converts small Kana characters to their equivalent full-size Kana, improving legibility in Japanese text.
  • math-auto: Automatically renders text in mathematical italic where appropriate, transforming Latin and Greek letters and specific math-related symbols to italic mathematical symbols.

Global Values

  • inherit: Inherits the value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Rolls back the value to the browser’s default.
  • revert-layer: Rolls back the value to the default of the cascade layer.
  • unset: Resets the property to its natural value, which means it behaves like inherit if the property is inherited or initial if it is not.

Summary

The formal definition of the text-transform property provides a clear structure for how text capitalization can be controlled in CSS. By understanding the initial value, applicable elements, inheritance, computed value, animation type, and formal syntax, developers can effectively use the text-transform property to enhance the readability and visual appeal of their web content. This property is a valuable tool for creating consistent and professional web designs that meet the needs of both developers and users.

Formal Syntax

The formal syntax for the text-transform property in CSS is designed to ensure a structured and consistent way to control text capitalization. The syntax is intuitive and easy to implement, allowing developers to specify how text should be transformed within an HTML element. Here is the formal syntax for the text-transform property:

text-transform =
none |
[ capitalize | uppercase | lowercase ] |
full-width |
full-size-kana |
math-auto |
inherit | initial | revert | revert-layer | unset;

Keyword Values

  • none: No transformation is applied, and the text remains as it is written.
  • capitalize: Transforms the first letter of each word to uppercase while leaving the rest of the letters unchanged.
  • uppercase: Converts all characters in the text to uppercase.
  • lowercase: Converts all characters in the text to lowercase.
  • full-width: Forces characters to be displayed in a full-width format, useful for aligning text with East Asian scripts like Chinese or Japanese.
  • full-size-kana: Converts small Kana characters to their equivalent full-size Kana, improving legibility in Japanese text.
  • math-auto: Automatically renders text in mathematical italic where appropriate, transforming Latin and Greek letters and specific math-related symbols to italic mathematical symbols.

Global Values

  • inherit: Inherits the value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Rolls back the value to the browser’s default.
  • revert-layer: Rolls back the value to the default of the cascade layer.
  • unset: Resets the property to its natural value, which means it behaves like inherit if the property is inherited or initial if it is not.

Example

Here’s an example of how to use the text-transform property with the formal syntax:

p {
text-transform: uppercase;
}

In this example, all paragraph (<p>) text will be transformed to uppercase.

Summary

The formal syntax of the text-transform property provides a clear and structured way to control text capitalization in CSS. By understanding and using the correct syntax and values, developers can enhance the readability and visual appeal of their web content. Whether you need to capitalize headings, convert text to uppercase, or improve the legibility of mathematical expressions, the text-transform property offers the flexibility to achieve your desired text effects.

Specifications

The text-transform property is defined in the CSS Text Module Level 3 specification.

icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.