JavaScript String italics() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype.italics() is a legacy HTML wrapper that returns a new string wrapping your text in <i>…</i>. It takes no parameters and never mutates the original string.

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

Syntax

Call string.italics. Start with this line.

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

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

Library declarations
JavaScript
string.italics()

Parameters

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

Return Value

Return ValueDescription
*HTML string with <i> tags

JavaScript Examples

Example 1 — Basic Wrap

Call italics() to build the classic <i> HTML string.

JavaScript
const text = "Hello, world";

console.log(text.italics());
// "<i>Hello, world</i>"
Try It Yourself

How It Works

  1. Start with text. "Hello, world" is a normal string.
  2. Call italics(). No arguments — the method wraps the whole string.
  3. Get HTML markup. The return value is "<i>Hello, world</i>".
  4. Original stays put. text is still "Hello, world".

Example 2 — Empty String & Special Characters

See empty wrappers and that < is not escaped.

JavaScript
console.log("".italics());       // "<i></i>"
console.log("A < B".italics());  // "<i>A < B</i>"
console.log(typeof "x".italics()); // "string"
Try It Yourself

How It Works

  1. Empty input. "".italics() still wraps tags around nothing → "<i></i>".
  2. No escaping. "A < B" keeps the < character inside the markup.
  3. Type is string. You get text, not a live DOM element.
  4. Safety tip. Never feed untrusted input through italics() into innerHTML.

Example 3 — Prefer DOM / CSS Instead

Compare the legacy wrapper with modern createElement and font-style.

JavaScript
// Legacy — do not use in new code
console.log("term".italics());
// "<i>term</i>"

// Prefer a real element
const el = document.createElement("i");
el.textContent = "term";
console.log(el.outerHTML);
// "<i>term</i>"

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

How It Works

  1. Legacy path. "term".italics() builds an HTML string via the deprecated method.
  2. Create a real element. createElement("i") + textContent is the safe DOM approach.
  3. Look-only italics. CSS font-style: italic needs no special tag.
  4. Rule of thumb. Learn italics() to read old code; ship DOM/CSS for new UI.

Browser & Runtime Support

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

✓ Deprecated · Legacy

String.prototype.italics()

Available in major browsers and Node.js for legacy compatibility. Prefer DOM APIs or CSS font-style in new code.

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() when reading old code. For new UI, use createElement("i") / "em" or CSS font-style: italic — never ship wrapper strings from string methods.

Frequently Asked Questions

italics() returns a new HTML string that wraps the text in an <i> element — for example "Hello".italics() returns "<i>Hello</i>". It takes no parameters and does not change the original string.
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.

Next: link()

Another deprecated HTML wrapper — this one builds <a href> markup from a string.

link() 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.

7 people found this page helpful