Generate Superscript and Subscript HTML Code
Use <sup> for raised text, such as a mathematical exponent or footnote marker, and <sub> for lowered text, such as a chemical formula’s atom count. Choose the type, enter the characters to format, and copy the generated HTML into your page.
Only wrap the part that needs to move above or below the baseline. For example, use x<sup>2</sup> for a squared variable and H<sub>2</sub>O for water. The generator also provides Python code to create these elements in an HTML document with
Aspose.HTML for Python via .NET
.
Superscript and Subscript Generator Settings
- Type selects superscript for a
<sup>element or subscript for a<sub>element. Choose the type before entering your text, because changing it restores the corresponding sample text. - Text supplies the characters inside the selected element. Enter just the exponent, index, or marker rather than the complete expression. HTML typed into this field is treated as text, not as nested markup.
The preview and generated HTML include a fixed normal-text phrase to show the baseline. Replace that phrase with your surrounding content when adding the result to your page. The tool does not include font, color, or text-size controls.
Use these tags when the raised or lowered position carries meaning, rather than for purely decorative text placement. See the HTML references for superscript and subscript .
Create Superscript or Subscript in Python
Use
HTMLDocument
to create a document containing ordinary text and a sup or sub element. The example assigns the selected text, appends the element to the body, and saves the HTML file.
The Python code updates when you change the type or text. Replace the sample baseline text with the surrounding words or symbols for your formula, exponent, or note marker.
import aspose.html
with aspose.html.HTMLDocument() as document:
document.body.text_content = "This is normal text "
element = document.create_element("sup")
element.text_content = "This is superscript"
document.body.append_child(element)
document.save("superscript.html")
Steps to Create Superscript or Subscript in Python
- Create an
HTMLDocumentand set the ordinary baseline text indocument.body.text_content. - Call
create_element()with"sup"or"sub"to create the required element. - Assign the characters to format through
text_content. - Append the element to
document.bodywithappend_child(). - Save the HTML document with
save(). Thewithstatement closes the document automatically.
HTML Superscript and Subscript Generator FAQ
1. How do I add both superscript and subscript to one symbol in HTML?
You can place separate <sub> and <sup> elements after a symbol, but ordinary HTML does not guarantee that the two indices will align vertically in the same column. For mathematical notation that requires an upper and lower index attached to the same base, use MathML’s
msubsup element
. This generator creates one HTML index element at a time.
2. How do I make a superscript footnote number clickable in HTML?
Place an <a> link inside the <sup> marker and point its href to the note’s ID elsewhere on the page. Add the note text and matching ID separately. The
HTML Hyperlink Generator
can create the link markup. A superscript marker alone does not generate, number, or link footnotes automatically.
3. Why is superscript or subscript not working in HTML?
Check that your editor accepts HTML and preserves the <sup> or <sub> element. Paste the markup into an HTML editing mode or custom HTML block rather than a plain-text field. If the tags remain but the position is wrong, check whether your website’s CSS overrides their vertical-align or font-size styles.
Install Aspose.HTML for Python via .NET
Install the aspose-html-net package from
PyPI
.
Install Aspose.HTML for Python via .NET
pip install aspose-html-net
Review the installation guide and system requirements before deployment. Request a temporary license to test the API without evaluation limitations.
Related HTML Generators for Python
Add links, tables, images, and other elements to your HTML documents.