String.prototype.fixed() is a legacy HTML wrapper that returns a new string wrapping your text in <tt>…</tt> (historically a fixed-width / teletype font). 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.fixed. Start with this line.
JavaScript
string.fixed()
Call
What it does
string.fixed()
Primary signature.
string.fixed(...)
Call with the arguments your case needs.
Built into JavaScript. Call fixed(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
string.fixed()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
HTML string with obsolete <tt> tags
JavaScript Examples
Example 1 — Basic Wrap
Call fixed() to build the classic <tt> HTML string.
JavaScript
const text = "Hello, world";
console.log(text.fixed());
// "<tt>Hello, world</tt>"
Empty input."".fixed() still wraps tags around nothing → "<tt></tt>".
No escaping."A < B" keeps the < character inside the markup.
Type is string. You get text, not a live DOM element.
Safety tip. Never feed untrusted input through fixed() into innerHTML.
Example 3 — Prefer CSS / <code>
Compare the legacy wrapper with a modern, semantic approach.
JavaScript
// Legacy — do not use in new code
console.log("npm start".fixed());
// "<tt>npm start</tt>"
// Prefer DOM + semantic code
const el = document.createElement("code");
el.textContent = "npm start";
console.log(el.outerHTML);
// "<code>npm start</code>"
// Or style only: el.style.fontFamily = "monospace";
Create a real element.createElement("code") is valid HTML for inline code.
Set plain text.textContent is safer than injecting markup strings.
Rule of thumb. Learn fixed() to read old code; ship CSS or <code> for new UI.
Compatibility
Browser & Runtime Support
String.prototype.fixed() is still implemented widely for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.prototype.fixed()
Available in major browsers and Node.js for legacy compatibility. Prefer CSS font-family: monospace or <code> for new code.
LegacyCompatibility only
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
fixed()Avoid in new code
Bottom line: Recognize fixed() when reading old code. For new UI, use CSS monospace or create a <code> element with textContent — never build obsolete <tt> markup with string wrappers.
Frequently Asked Questions
fixed() returns a new HTML string that wraps the text in a <tt> element — for example "Hello".fixed() returns "<tt>Hello</tt>". It takes no parameters and does not change the original string.
Yes. MDN marks all HTML wrapper methods as deprecated. The <tt> element itself was removed from the HTML specification. Prefer CSS font-family: monospace, or semantic tags like <code> when the meaning fits.
The <tt> element is obsolete. Modern HTML expects monospace styling from CSS, or semantic elements such as <code>, <kbd>, or <samp> when appropriate.
No. Strings are immutable. fixed() returns a new string containing HTML markup; the original text stays the same.
Set CSS font-family to a monospace stack, or use document.createElement("code") with textContent for inline code. Avoid building <tt> strings.
No. Characters like < and > are left as-is inside the wrapper. Never pass untrusted user input through fixed() into innerHTML.