w3resource

HTML5: How to define subscripted text?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Define document type as HTML -->
<html><!-- Begin HTML document -->
<head><!-- Start of document header -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to define subscripted text</title><!-- Title of the HTML page -->
</head><!-- End of document header -->
<body><!-- Start of document body -->
<p>This text is<sub>subscript</sub> text.example- H<sub>2</sub>O </p><!-- Paragraph element containing subscripted text -->
</body><!-- End of document body -->
</html><!-- End of HTML document -->

Explanation:

  • This HTML code defines a webpage with a paragraph containing subscripted text.
  • The <sub> tag is used to define subscripted text within the paragraph.
  • The text "subscript" inside the <sub> tags will be displayed in a smaller font size and lowered position compared to the surrounding text.
  • The text "H<sub>2</sub>O" demonstrates the use of subscript for chemical formulas, where "2" is displayed in subscript.

Live Demo:

See the Pen style-type-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
Yes Yes Yes Yes Yes

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.