JavaScript String small() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated

What You’ll Learn

String.prototype.small() is a deprecated HTML wrapper method (same API as MDN String.prototype.small()). It returns a string that wraps your text in a <small> tag. Learn what it builds, why wrappers are discouraged, and how to replace them with DOM APIs or CSS — with five examples and try-it labs.

01

Kind

Instance method

02

Returns

HTML string

03

Status

Deprecated

04

Params

None

05

Mutates?

No

06

Prefer

createElement

Introduction

Early JavaScript included helpers that wrapped text in HTML tags — small(), big(), bold(), italics(), and others. They made it easy to inject markup with innerHTML.

Today those wrappers are deprecated. small() still works in browsers for compatibility. The <small> element remains valid HTML (fine print / side comments), but you should create it with the DOM — not by concatenating tags as a string.

💡
Learn it, don’t ship it

Study small() so you can recognize legacy code. For new pages, use document.createElement("small") or a CSS class for smaller text.

This page is part of JavaScript String Methods. Related topics include big() and link().

Understanding the small() Method

Calling str.small() does not create a live DOM node and does not take arguments. It concatenates an HTML string: <small> + text + </small>.

  • It is an instance method on strings (auto-boxed if needed).
  • It returns a new string — the original is unchanged.
  • No parameters — just str.small().
  • Prefer createElement("small") or CSS for real UI.

📝 Syntax

General form of String.prototype.small:

JavaScript
str.small()

Parameters

None.

Return value

A string beginning with a <small> start tag, then the text of str, then a </small> end tag.

Common patterns

JavaScript
"Hello, world".small();
// 'Hello, world'

// Prefer this in new code:
const elem = document.createElement("small");
elem.textContent = "Hello, world";
document.body.appendChild(elem);

⚡ Quick Reference

GoalCode
Legacy HTML stringstr.small()
Result shape<small>...</small>
Modern DOMdocument.createElement("small")
Use in new apps?No — deprecated method

🔍 At a Glance

Four facts to remember about String.small().

Returns
string

HTML markup text

Status
deprecated

Compatibility only

Tag
<small>

Still valid HTML

Replace with
createElement

Or CSS font-size

📋 small() vs createElement("small")

str.small()createElement("small")
ResultHTML stringLive DOM element
<small> valid today?Tag yes; method noYes — preferred
Recommended?NoYes
Best forReading legacy codeNew UI / apps

Examples Gallery

Examples follow MDN String.small() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

See the exact HTML string small() builds.

Example 1 — Basic small()

MDN-style call that wraps text in <small>.

JavaScript
const contentString = "Hello, world";
contentString.small();
// 'Hello, world'
Try It Yourself

How It Works

The method returns markup text only. Nothing is added to the document until you assign it somewhere (for example innerHTML).

Example 2 — Empty String and Special Characters

Tags are still produced for empty text; content is not HTML-escaped.

JavaScript
"".small();           // ''
"A < B".small();      // 'A < B'
typeof "x".small();   // "string"
Try It Yourself

How It Works

Unlike some attribute wrappers, small() does not escape < inside the text. That is another reason to avoid injecting untrusted strings via innerHTML.

📈 Practical Patterns

Legacy injection patterns and the modern DOM replacement.

Example 3 — Injecting with innerHTML (Legacy)

How older demos used the returned string — MDN’s classic pattern.

JavaScript
const contentString = "Hello, world";
const html = contentString.small();
// document.body.innerHTML = html;  // legacy pattern — avoid in new apps

console.log(html);
// Prefer createElement("small") instead
Try It Yourself

How It Works

Browsers still understand <small>, but building it as a string skips safer DOM APIs and makes XSS easier if content is untrusted.

Example 4 — Other HTML Wrappers Nearby

Recognize the same pattern family — all deprecated.

JavaScript
"Hi".small();   // 'Hi'
"Hi".big();     // 'Hi'
"Hi".bold();    // 'Hi'
"Hi".italics(); // 'Hi'
Try It Yourself

How It Works

These helpers share one idea: return presentational HTML strings. Modern code creates elements with the DOM (and CSS when size is only visual).

Example 5 — Modern Replacement with createElement

MDN’s recommended approach — build a real <small> node.

JavaScript
const contentString = "Hello, world";
const elem = document.createElement("small");
elem.textContent = contentString;

// document.body.appendChild(elem);
console.log(elem.tagName);
console.log(elem.outerHTML);
Try It Yourself

How It Works

You get a live element, safer text assignment via textContent, and markup that matches modern HTML practice. Use CSS font-size when you only need smaller visual size without fine-print semantics.

🚀 Common Use Cases

  • Reading legacy tutorials — recognize HTML wrapper methods in old samples.
  • Migrating old scripts — replace small() with createElement("small").
  • Fine print / disclaimers — use a real <small> element (not the string method).
  • Teaching string immutability — show that methods return new strings.
  • Not for new apps — do not use small() to shrink UI text.
  • Safer markup — prefer textContent + DOM over innerHTML strings.

🧠 How small() Builds Markup

1

Start with text

You call str.small() on a string receiver.

Input
2

Wrap with tags

Concatenate <small> + text + </small>.

Wrap
3

Return an HTML string

No DOM node is created — only text markup.

Result
4

Prefer the DOM instead

Create a real <small> with createElement.

📝 Notes

  • small() is deprecated — standardized only for compatibility.
  • The <small> element is still valid HTML; the string method is not recommended.
  • It returns a string, not a DOM node.
  • It takes no parameters.
  • Other HTML wrappers (big(), bold(), fontcolor(), …) share the same fate.
  • Avoid assigning untrusted strings to innerHTML.

Browser & Runtime Support

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

Deprecated · Legacy

String.small()

Available in modern browsers for old code, but MDN recommends document.createElement("small") instead.

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
small() Avoid in new code

Bottom line: Recognize small() in legacy samples. For new UI, create a real element with the DOM — or use CSS font-size when size is only visual.

Conclusion

String.prototype.small() builds a <small>...</small> HTML string. It is useful for understanding history and migrating old code — not for writing new features.

Continue with strike(), at(), or the String methods hub.

💡 Best Practices

✅ Do

  • Use createElement("small") for fine print
  • Use CSS font-size when size is only visual
  • Prefer textContent over string-built HTML
  • Replace small() when you touch legacy files
  • Learn wrappers only to recognize deprecated APIs

❌ Don’t

  • Use small() in new production code
  • Confuse the valid <small> element with the deprecated method
  • Inject untrusted small() output via innerHTML
  • Expect small() to return a live element
  • Mix HTML wrappers with modern component frameworks

Key Takeaways

Knowledge Unlocked

Five things to remember about String.small()

Deprecated HTML wrapper — prefer createElement.

5
Core concepts
⚠️ 02

Status

deprecated

Legacy
03

Element

still valid

HTML
04

Replace

createElement

Modern
05

Mutates

no

Immutable

❓ Frequently Asked Questions

String.prototype.small() returns an HTML string that wraps the text in a <small> element — for example "Hello".small() returns '<small>Hello</small>'. It takes no parameters.
Yes. MDN marks all HTML wrapper methods as deprecated. Prefer document.createElement("small") or CSS font-size instead of building markup with string methods.
Yes. Unlike <big>, the <small> element remains in HTML for side comments and fine print. What is deprecated is the String.small() helper that builds that markup as a string.
No. Strings are immutable. small() returns a new string containing HTML markup. The original text stays the same.
Use document.createElement("small") and set textContent, or style an element with CSS font-size / a utility class. Avoid injecting string-built HTML via innerHTML when you can create real nodes.
It remains widely available for compatibility, but you should not use it in new code.
Did you know?

HTML once had both <big> and <small> for relative font size. <small> survived with a semantic meaning (side comments / fine print), while <big> was removed — yet String.prototype.small() is still a deprecated string helper, just like big().

More String Methods

Return to the hub for slice, trim, replace, and more.

String methods hub →

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