JavaScript String strike() Method

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

What You’ll Learn

String.prototype.strike() is a deprecated HTML wrapper method (same API as MDN String.prototype.strike()). It returns a string that wraps your text in a <strike> tag. Learn what it builds, why that element is obsolete, and how to replace it with <s> / <del> — 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

<s> or <del>

Introduction

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

Today those wrappers are deprecated. strike() still works in browsers for compatibility, but the <strike> element itself was removed from HTML. Use semantic strikethrough with <s> or <del> instead.

💡
Learn it, don’t ship it

Study strike() so you can recognize legacy code. For new pages, create a real <s> or <del> node — or use CSS text-decoration: line-through when the look is only visual.

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

Understanding the strike() Method

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

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

📝 Syntax

General form of String.prototype.strike:

JavaScript
str.strike()

Parameters

None.

Return value

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

Common patterns

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

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

⚡ Quick Reference

GoalCode
Legacy HTML stringstr.strike()
Result shape<strike>...</strike>
Modern inaccurate textdocument.createElement("s")
Modern deleted textdocument.createElement("del")
Use in new apps?No — deprecated

🔍 At a Glance

Four facts to remember about String.strike().

Returns
string

HTML markup text

Status
deprecated

Compatibility only

Tag
<strike>

Removed from HTML

Replace with
<s> / <del>

Semantic elements

📋 strike() vs <s> vs <del>

str.strike()<s><del>
ResultHTML stringLive elementLive element
Valid HTML today?No (<strike> removed)YesYes
MeaningPresentational onlyNo longer accurate / relevantDeleted content
Recommended?NoYes (when accurate)Yes (for edits)

Examples Gallery

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

📚 Getting Started

See the exact HTML string strike() builds.

Example 1 — Basic strike()

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

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

How It Works

Unlike some attribute wrappers, strike() 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 — still produces obsolete markup.

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

console.log(html);
// Warning:  is not a valid element in modern HTML
Try It Yourself

How It Works

Even if a browser still draws a line through <strike> text, the element is obsolete. Prefer <s> or <del>.

Example 4 — Other HTML Wrappers Nearby

Recognize the same pattern family — all deprecated.

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

How It Works

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

Example 5 — Modern Replacement with createElement("s")

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

JavaScript
const contentString = "Hello, world";
const elem = document.createElement("s");
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 and valid markup. Use <del> when the text was removed as an edit; use CSS line-through when the look is only decorative.

🚀 Common Use Cases

  • Reading legacy tutorials — recognize HTML wrapper methods in old samples.
  • Migrating old scripts — replace strike() with createElement("s") or "del".
  • Price / outdated labels — use a real <s> for “no longer accurate” text.
  • Document edits — use <del> (often with <ins>) for tracked changes.
  • Not for new apps — do not use strike() to draw strikethrough.
  • Safer markup — prefer textContent + DOM over innerHTML strings.

🧠 How strike() Builds Markup

1

Start with text

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

Input
2

Wrap with tags

Concatenate <strike> + text + </strike>.

Wrap
3

Return an HTML string

No DOM node is created — only text markup.

Result
4

Prefer <s> / <del> instead

Create a semantic element with createElement.

📝 Notes

  • strike() is deprecated — standardized only for compatibility.
  • The <strike> element was removed from the HTML specification.
  • Prefer <s> (inaccurate / irrelevant) or <del> (deleted content).
  • It returns a string, not a DOM node.
  • It takes no parameters.
  • Avoid assigning untrusted strings to innerHTML.

Browser & Runtime Support

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

Deprecated · Legacy

String.strike()

Available in modern browsers for old code, but MDN recommends createElement("s") or createElement("del") 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
strike() Avoid in new code

Bottom line: Recognize strike() in legacy samples. For new UI, create a real or element — never rely on the obsolete tag from HTML wrapper methods.

Conclusion

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

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

💡 Best Practices

✅ Do

  • Use <s> for text that is no longer accurate
  • Use <del> for deleted / edited-out content
  • Prefer textContent over string-built HTML
  • Replace strike() when you touch legacy files
  • Learn wrappers only to recognize deprecated APIs

❌ Don’t

  • Use strike() in new production code
  • Assume <strike> is valid modern HTML
  • Inject untrusted strike() output via innerHTML
  • Expect strike() to return a live element
  • Mix HTML wrappers with modern component frameworks

Key Takeaways

Knowledge Unlocked

Five things to remember about String.strike()

Deprecated HTML wrapper — prefer <s> or <del>.

5
Core concepts
⚠️ 02

Status

deprecated

Legacy
03

Markup

invalid

HTML
04

Replace

<s> / <del>

Modern
05

Mutates

no

Immutable

❓ Frequently Asked Questions

String.prototype.strike() returns an HTML string that wraps the text in a <strike> element — for example "Hello".strike() returns '<strike>Hello</strike>'. It takes no parameters.
Yes. MDN marks all HTML wrapper methods as deprecated. The <strike> element itself was removed from the HTML specification. Prefer <s> or <del> created with document.createElement().
The <strike> element is obsolete. Modern HTML uses <s> for content that is no longer accurate or relevant, and <del> for deleted content (often with an edit history).
No. Strings are immutable. strike() returns a new string containing HTML markup. The original text stays the same.
Use document.createElement("s") or document.createElement("del"), and set textContent. You can also style text with CSS text-decoration: line-through when the meaning is purely visual.
It remains widely available for compatibility, but you should not use it in new code.
Did you know?

<strike> and <s> both drew a line through text historically, but modern HTML dropped <strike> and kept <s> with a clearer meaning (content that is no longer accurate or relevant). <del> is for deletions — often paired with <ins>.

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