JavaScript String italics() Method

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

What You’ll Learn

String.prototype.italics() is a deprecated HTML wrapper method (same API as MDN String.prototype.italics()). It returns a string that wraps your text in an <i> tag. Learn what it builds, how <i> differs from <em>, and how to replace the wrapper 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

DOM / font-style

Introduction

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

Today those wrappers are deprecated. italics() may still return a string for compatibility. The <i> element remains valid HTML, but you should create it with the DOM (or use CSS / <em>) — not string methods.

💡
Learn it, don’t ship it

Study italics() so you can recognize legacy code. For new pages, create real elements with document.createElement() or apply font-style: italic instead of building <i> strings.

This page is part of JavaScript String Methods. Related topics include bold() and fontsize().

Understanding the italics() Method

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

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

📝 Syntax

General form of String.prototype.italics:

JavaScript
str.italics()

Parameters

None.

Return value

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

SituationReturns
Normal text"Hi".italics()'<i>Hi</i>'
Empty string"".italics()'<i></i>'
Text with <Not escaped — e.g. "A < B".italics() keeps the raw <
Type of resultAlways a string (not a DOM node)

Common patterns

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

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

// Or style only (no semantic tag):
// el.style.fontStyle = "italic";

⚡ Quick Reference

GoalCode
Legacy HTML stringstr.italics()
Result shape<i>...</i>
Modern DOMdocument.createElement("i")
Look-only italicsel.style.fontStyle = "italic"
Stress emphasisdocument.createElement("em")
Use in new apps?No — deprecated

🔍 At a Glance

Four facts to remember about String.italics().

Returns
string

HTML markup text

Status
deprecated

Compatibility only

Tag
<i>

Still valid HTML

Replace with
createElement

DOM / font-style

📋 italics() vs DOM vs CSS

str.italics()createElement("i")font-style: italic
ResultHTML stringLive DOM elementStyle on any element
Valid HTML today?Yes (tag OK; method deprecated)YesYes (CSS)
Recommended?NoYes (when you need <i>)Yes (look only)
Best forReading legacy codeSemantic / structural markupVisual italics without a tag

Examples Gallery

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

📚 Getting Started

See the exact HTML string italics() builds.

Example 1 — Basic italics()

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

JavaScript
const contentString = "Hello, world";
contentString.italics();
// '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
"".italics();           // ''
"A < B".italics();      // 'A < B'
typeof "x".italics();   // "string"
Try It Yourself

How It Works

Unlike some attribute wrappers, italics() 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 / CSS replacements.

Example 3 — Injecting with innerHTML (Legacy)

How older demos used the returned string — prefer the DOM in new apps.

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

console.log(html);
// Prefer createElement("i") in new apps
Try It Yourself

How It Works

The returned string is only markup text. Prefer creating a real <i> or <em> element with the DOM instead of assigning HTML strings.

Example 4 — Other HTML Wrappers Nearby

Recognize the same pattern family — all deprecated.

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

How It Works

These helpers share one idea: return presentational HTML strings. Modern code styles elements with CSS (and semantic tags when needed).

Example 5 — Modern Replacement with the DOM and CSS

MDN’s recommended approach — create a real element, or use CSS for look-only italics.

JavaScript
const contentString = "Hello, world";

const elem = document.createElement("i");
elem.textContent = contentString;
// document.body.appendChild(elem);

console.log(elem.tagName);
console.log(elem.outerHTML);

// Look-only alternative:
const styled = document.createElement("span");
styled.textContent = contentString;
styled.style.fontStyle = "italic";
console.log(styled.style.fontStyle);
Try It Yourself

How It Works

You get a live element you can style, attach listeners to, and keep separate from untrusted HTML concatenation. Use <em> when the meaning has stress emphasis, or CSS font-style for look only.

🚀 Common Use Cases

  • Reading legacy tutorials — recognize HTML wrapper methods in old samples.
  • Migrating old scripts — replace italics() with createElement() or CSS font-style.
  • Teaching string immutability — show that methods return new strings.
  • Not for new apps — do not use italics() to build HTML in new apps.
  • Semantic emphasis — prefer <em> for stress and CSS for look-only italics.
  • Safer markup — prefer textContent + CSS over innerHTML strings.

🧠 How italics() Builds Markup

1

Start with text

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

Input
2

Wrap with tags

Concatenate <i> + text + </i>.

Wrap
3

Return an HTML string

No DOM node is created — only text markup.

Result
4

Prefer the DOM / CSS

Create a real <i> or <em>, or set font-style: italic.

📝 Notes

  • italics() is deprecated — standardized only for compatibility.
  • The method is deprecated; the <i> element itself remains valid HTML.
  • <i> is for alternate voice/style; <em> marks stress emphasis — pick the right one.
  • It returns a string, not a DOM node.
  • It takes no parameters.
  • Other HTML wrappers (bold(), big(), blink(), …) share the same fate.
  • Avoid assigning untrusted strings to innerHTML.

Browser & Runtime Support

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

Deprecated · Legacy

String.italics()

Available in modern browsers for old code, but MDN recommends DOM APIs such as createElement() 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
italics() Avoid in new code

Bottom line: Recognize italics() in legacy samples. For new UI, create elements with the DOM or use CSS font-style — never rely on HTML wrapper string methods.

Conclusion

String.prototype.italics() builds an <i>...</i> HTML string. The method is deprecated — useful for history and migrating old code — not for writing new features.

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

💡 Best Practices

✅ Do

  • Use document.createElement("i") or CSS font-style
  • Use <em> when the text has stress emphasis
  • Prefer textContent over string-built HTML
  • Replace italics() when you touch legacy files
  • Learn wrappers only to recognize deprecated APIs

❌ Don’t

  • Use italics() in new production code
  • Assume string-built HTML is the best way to italicize text
  • Inject untrusted italics() output via innerHTML
  • Expect italics() to return a live element
  • Mix HTML wrappers with modern component frameworks

Key Takeaways

Knowledge Unlocked

Five things to remember about String.italics()

Deprecated HTML wrapper — prefer createElement or CSS font-style.

5
Core concepts
⚠️ 02

Status

deprecated

Legacy
03

Markup

<i> OK

HTML
04

Replace

DOM / font-style

Modern
05

Mutates

no

Immutable

❓ Frequently Asked Questions

String.prototype.italics() returns an HTML string that wraps the text in an <i> element — for example "Hello".italics() returns '<i>Hello</i>'. It takes no parameters.
Yes. MDN marks all HTML wrapper methods as deprecated. Prefer document.createElement(), CSS font-style: italic, or a semantic <em> element when the text needs emphasis.
Yes. Unlike <blink> or <big>, <i> is still in HTML. Use it for alternate voice or style (for example a technical term). Use <em> when the text has stress emphasis, or CSS font-style for look-only italics.
No. Strings are immutable. italics() returns a new string containing HTML markup. The original text stays the same.
Use document.createElement("i") or createElement("em"), set textContent, and append the element. Or apply CSS font-style: italic without building HTML strings.
It remains widely available for compatibility, but you should not use it in new code. Prefer DOM APIs or CSS.
Did you know?

HTML keeps both <i> and <em>. Use <i> for an alternate voice or style (a foreign phrase, a taxonomic name), and <em> when the meaning has stress emphasis. CSS font-style: italic covers look-only italics.

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