Home >Web Front-end >CSS Tutorial >How Can I Capitalize the First Letter of a String Using CSS?

How Can I Capitalize the First Letter of a String Using CSS?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-09 10:39:09756browse

How Can I Capitalize the First Letter of a String Using CSS?

Capitalize First Character in CSS with the text-transform Property

Transforming text in CSS is a versatile technique that can lead to professional-looking results with minimal effort. One commonly sought-after approach is to capitalize the first character of a string, ensuring that text appears in title case.

In HTML, wrap the desired text within an element, such as an anchor tag:

<a class="m_title" href="">gorr</a>
<a class="m_title" href="">trro</a>
<a class="m_title" href="">krro</a>
<a class="m_title" href="">yrro</a>
<a class="m_title" href="">gwwr</a>

To capitalize the first letter, apply the text-transform: capitalize; rule to the element using a class selector:

a.m_title {
  text-transform: capitalize;
}

This property instructs the browser to format the text as title case, capitalizing the first character of each word.

With the CSS rule in place, your text will now appear with the first character capitalized:

<a class="m_title" href="">Gorr</a>
<a class="m_title" href="">Trro</a>
<a class="m_title" href="">Krro</a>
<a class="m_title" href="">Yrro</a>
<a class="m_title" href="">Gwwr</a>

The above is the detailed content of How Can I Capitalize the First Letter of a String Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn