How to change the cases of text in paragraph using CSS?


CSS (Cascading Style Sheets) is a powerful tool for controlling the layout and appearance of text on a website. In this article we will learn how to change the cases of text in paragraphs using CSS.

When it comes to styling text on a website, one of the basic and common styling options is changing the case of the text, and we can do this easily with the text-transform property in CSS. The text-transform property can take one of the following values −

  • "capitalize" will capitalize the first letter of each word in the selected element.

  • "uppercase" will convert all the text in the selected element to uppercase letters.

  • "lowercase" will convert all the text in the selected element to lowercase letters.

To change the case of text in a paragraph, firstly we will need to select the paragraph element using a CSS selector. For example, to change the case of text in a paragraph to uppercase, we will use the following CSS −

p {
   text-transform: uppercase;
} 

Example

Here is an example to change the cases of text in paragraphs using CSS.

<html>
<head>
   <title>Change the cases of text in paragraphs using CSS</title>
   <style>
      body{
         text-align:center;
      }
      .capitalize{
         color: blue;
         text-transform: capitalize;
      }
      .uppercase{
         color: red;
         text-transform: uppercase;
      }
      .lowercase{
         color: green;
         text-transform: lowercase;
      }
   </style>
</head>
<body>
   <h2>Change the cases of text in paragraphs using CSS</h2>
   <p class="capitalize">capitalize the first letter of each word in the selected element</p>
   <p class="uppercase">Converted all the text in the selected element to uppercase letters</p>
   <p class="lowercase">CONVERTED ALL THE TEXT IN SELECTES ELEMENT TO LOWERCASE LETTERS</p>
</body>
</html>

Conclusion

To change the cases of text in paragraphs, the text-transform property in CSS is a great way to change the case of text in a paragraph.

Updated on: 09-Mar-2023

523 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements