HTML sub tag


The sub tag in HTML is designed to display subscript characters, which are typically rendered as characters slightly below the baseline and in a smaller font size than the surrounding text. This tag is widely used in mathematical equations, chemical formulas, and other scientific expressions where certain elements or numbers need to be visually distinct as belonging to a lower textual level. The sub tag semantic meaning is of great importance, not only for those writing technical documents but also for web developers who aim to ensure that their content is accessible and semantically correct.


The primary use of the sub tag is within mathematical or scientific contexts where subscript is necessary. For instance, when denoting the chemical formula for water, H2O, the "2" should be in subscript. Similarly, in mathematical expressions, such as exponents, the sub tag finds a significant use case.

To apply subscript formatting using the sub tag, you simply wrap the text that needs to be subscripted within <sub> and </sub> tags. Here is an example:

<p>This is normal text with <sub>subscript</sub> text included.</p>

This will result in the word "subscript" being displayed in a smaller font size and slightly below the line of other text.

Styling with CSS

While the sub tag comes with default browser styling, it’s possible to customize its appearance using CSS. This can include changing the font size, vertical alignment, or color. Customizing the sub tag with CSS allows for more control over the presentation while maintaining the semantic meaning of the content.

For example, to change the color and font size of all sub elements:

sub {
  color: red;
  font-size: 75%;

This CSS rule will make all subscript text red and reduce its font size to 75% of its parent element’s font size.

Accessibility Considerations

Semantic HTML plays a crucial role in making web content accessible to users with disabilities. The sub tag, by providing semantic meaning to subscript text, allows assistive technologies to understand and convey the difference between normal and subscript text to users. This is important in scientific and mathematical content where the meaning of the text can change significantly with the use of subscripts.

Developers should ensure that the usage of the sub tag does not solely rely on visual difference but also maintains its semantic integrity for assistive technologies. This involves avoiding the sub tag for stylistic purposes that do not align with its semantic purpose.

Best Practices

  • Semantic Correctness: Use the sub tag only for text that semantically should be subscripted, such as in chemical formulas or mathematical expressions.
  • Avoid Stylistic Abuse: Do not use the sub tag purely for visual effect if the content does not semantically require being in subscript.
  • Test Readability: Since subscript text is smaller and can be harder to read, ensure that it remains legible across different devices and screen sizes. This may involve adjusting font sizes or line heights through CSS.
  • Accessibility: Regularly validate your use of the sub tag with accessibility tools to ensure that it does not hinder the experience of users relying on assistive technologies.


The sub tag serves a crucial role in web document semantics, especially within scientific, mathematical, and technical content. Its proper use not only enhances the readability and accessibility of web pages but also ensures that documents maintain their intended meaning across different viewing platforms. By adhering to best practices and considering accessibility at every turn, developers can leverage the sub tag to its full potential, making content understandable and accessible to all users.