Format Code Now
/
Web & markupHTML Subscript Generator Next: HTML Table Generator ›

HTML Subscript and Superscript Generator

WM-63

Wrap parts of a line in ~tildes~ for sub or ^carets^ for sup, or let the formula option subscript the digits in H2O for you.

Runs in your browser. Nothing is uploaded.

Text; wrap parts in ~tildes~ (subscript) or ^carets^ (superscript)

HTML

How to use it

  1. Type your text. Use ~2~ for subscript or ^2^ for superscript around the characters to raise or lower.
  2. Click Subscript (sub) or Superscript (sup).
  3. For chemical formulas, pick the formula option so digits after a letter become subscripts.
  4. Copy the HTML into your page.

When to use sub and sup

The sub element lowers text and sup raises it, for typographic reasons that the meaning depends on. Subscript is used in chemical formulas such as H2O and in mathematical indices such as log10. Superscript is used for exponents, as in E = mc2, and for ordinal endings such as 21st and for footnote reference numbers. Do not use them just to shrink or lift text for looks; use CSS for that.

The formula option

In formula mode, any digits that follow a letter or a closing bracket become subscripts, so H2O becomes H followed by a subscript 2 and O, and Ca(OH)2 gets its 2 lowered. The rule is simple on purpose: it will also lower the digits in words such as version2 or log10, so check the result. Marked parts with tildes still work in the same text. The formula option is only for the subscript action; the superscript action refuses it with a message.

Line spacing and styling

Browsers raise and lower the text with vertical-align and set a smaller size, and in many layouts that makes the line taller than its neighbours. A common fix is a stylesheet rule that sets line-height to 0 on sub and sup. The tool writes only the elements and the p tags around blocks; it adds no style. Markers stay on one line and do not nest, and everything else in your text is escaped.

Error messages and what to do

MessageWhat it meansFix
The formula option only works with the subscript action.Superscript was clicked while the formula option was selected.Click Subscript, or choose another option.

Questions people ask

How do I write H2O with a subscript in HTML?

Write H<sub>2</sub>O. In this tool type H~2~O, or pick the formula option and type H2O. The formula option wraps the 2 for you in a subscript element, so typing H2O is enough when you pick it.

What is the difference between sub and sup?

sub lowers the text, like the 2 in H2O. sup raises it, like the 2 in x squared or the st in 1st. Both are inline elements, so they sit inside a paragraph or heading and do not break the line by themselves.

Why do sub and sup change my line spacing?

The browser shifts the text up or down and that can push lines apart. A CSS rule with line-height: 0 on sub and sup usually fixes it.

Should I use Unicode subscript characters instead?

Sometimes, but not every font includes them and not every digit has one. The elements work with any text and are easy to restyle. Characters such as the small 2 may be read oddly by screen readers or missing in a font, so elements are safer in body text.

Can the generator handle ions like SO4 with a charge?

Not automatically. Write the charge in carets, for example SO~4~^2-^, and mark the parts yourself. The formula option does not guess charges, so SO4 with a charge needs the manual markers shown here.

About this tool

The subscript action wraps ~text~ in sub elements; the superscript action wraps ^text^ in sup elements. The formula option adds subscripts automatically, for any digits that follow a letter or a closing bracket (H2O, Ca(OH)2); it also changes things like version2 or log10, and it applies to the subscript action only. With no markers, whole lines are wrapped. Browsers lift or lower the text and can increase the line spacing; a CSS rule setting line-height: 0 on sub and sup avoids that. Markers do not nest or cross lines. Other text is escaped.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.