w3resource

CSS Properties: How to change cases of text in paragraphst

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Declares the document type and version of HTML -->
<html><!-- Begins the HTML document -->
<head><!-- Contains metadata and links to external resources -->
<title>How to change cases of text in paragraphs</title><!-- Sets the title of the document -->
<style type="text/css"> /* Starts CSS styling */
p.capitalize { /* Styles paragraphs with the class "capitalize" */
    text-transform: capitalize; /* Transforms text to capitalize the first character of each word */
}
p.uppercase { /* Styles paragraphs with the class "uppercase" */
    text-transform: uppercase; /* Transforms text to uppercase */
}
p.lowercase { /* Styles paragraphs with the class "lowercase" */
    text-transform: lowercase; /* Transforms text to lowercase */
}
</style><!-- Ends CSS styling -->
</head><!-- Ends the head section -->
<body><!-- Begins the body of the document -->
<h1><strong>w3resource Tutorial</strong></h1><!-- Displays a level 1 heading with bold text "w3resource Tutorial" -->
<h3>Text transform: capitalize</h3><!-- Displays a level 3 heading indicating the text transformation -->
<p class="capitalize">web development tutorial </p><!-- Displays a paragraph with the class "capitalize" and applies text capitalization -->
<h3>Text transform: uppercase</h3><!-- Displays a level 3 heading indicating the text transformation -->
<p class="uppercase">web development tutorial </p><!-- Displays a paragraph with the class "uppercase" and applies text uppercase -->
<h3>Text transform: lowercase</h3><!-- Displays a level 3 heading indicating the text transformation -->
<p class="lowercase">web development tutorial </p><!-- Displays a paragraph with the class "lowercase" and applies text lowercase -->
</body><!-- Ends the body section -->
</html><!-- Ends the HTML document -->

Explanation:

  • This HTML document demonstrates how to change the case of text in paragraphs using CSS.
  • Three CSS classes (capitalize, uppercase, and lowercase) are defined to apply different text transformations.
  • CSS comments are added to explain each section of the code.
  • The text-transform property is used to transform the text to capitalize, uppercase, or lowercase according to the specified class.

Live Demo:

See the Pen text-transform-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
YesYesYesYesYes

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.