JavaScript String sup() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype.sup() returns an HTML string that wraps your text in a <sup> tag (superscript). It is a deprecated HTML wrapper with no parameters and does not create a live DOM node.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call string.sup. Start with this line.

JavaScript
str.sup()
CallWhat it does
str.sup()Primary signature.
string.sup(...)Call with the arguments your case needs.

Built into JavaScript. Call sup(...) on a string (or String instance) — no import required.

Library declarations
JavaScript
str.sup()

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*HTML string: <sup>…</sup>

JavaScript Examples

Example 1 — Basic sup()

Wrap text in a <sup> HTML string. No parameters.

JavaScript
const exp = "2";

console.log(exp.sup());
// '<sup>2</sup>'

console.log(exp);  // "2" (unchanged)
Try It Yourself

How It Works

  1. Start with text. exp holds "2".
  2. Call the wrapper. sup() builds opening tag + text + closing tag.
  3. Get a string. The return value is markup text, not a painted element.
  4. Original stays put. Strings are immutable — exp is still "2".

Example 2 — sup() with sub()

See the matching pair of deprecated wrappers for superscript and subscript.

JavaScript
console.log("2".sup());
// '<sup>2</sup>'

console.log("2".sub());
// '<sub>2</sub>'

console.log("".sup());
// '<sup></sup>'
Try It Yourself

How It Works

  1. Superscript wrapper. sup() always builds <sup>…</sup>.
  2. Subscript sibling. sub() is the same idea with <sub>.
  3. Empty receiver. You still get opening and closing tags with nothing between.
  4. Both deprecated. Learn them to recognize old code — do not ship them.

Example 3 — Modern createElement("sup")

Create a real superscript node instead of building an HTML string.

JavaScript
const el = document.createElement("sup");
el.textContent = "2";

console.log(el.tagName);   // "SUP"
console.log(el.outerHTML); // '<sup>2</sup>'

// document.body.appendChild(el);
Try It Yourself

How It Works

  1. Create a real node. createElement("sup") gives you a live element.
  2. Set safe text. textContent avoids HTML injection from string-built tags.
  3. Valid HTML. The <sup> element is still correct for superscripts.
  4. Append when ready. Add the node to the document instead of assigning innerHTML.

Browser & Runtime Support

String.prototype.sup() is still widely implemented for compatibility, but it is deprecated. Do not use it in new projects.

✓ Deprecated · Legacy

String.sup()

Available in modern browsers for old code. MDN recommends createElement("sup") instead of string-built HTML wrappers.

Legacy Compatibility only
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
sup() Avoid in new code

Bottom line: Recognize sup() in legacy samples. For new UI, create a real <sup> element with createElement — the tag is valid; the string method is not recommended.

Frequently Asked Questions

String.prototype.sup() returns an HTML string that wraps the text in a <sup> element — for example "2".sup() returns '<sup>2</sup>'. It takes no parameters.
Yes. MDN marks all HTML wrapper methods as deprecated. Prefer document.createElement("sup") instead of building markup with string methods.
Yes. The <sup> element remains in HTML for superscript text (like x², ordinals, or footnotes). What is deprecated is the String.sup() helper that builds that markup as a string.
No. Strings are immutable. sup() returns a new string containing HTML markup. The original text stays the same.
Yes as a pair — sub() builds <sub> and sup() builds <sup>. Both are deprecated HTML wrappers. Prefer createElement("sub") / createElement("sup").
Use document.createElement("sup") and set textContent. Avoid injecting string-built HTML via innerHTML when you can create real nodes.

Next: String at()

Learn modern character access with negative indexes — no HTML wrappers involved.

at() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful