String.prototype.bold() is a legacy HTML wrapper that returns a new string wrapping your text in <b>…</b>. 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.bold. Start with this line.
JavaScript
string.bold()
Call
What it does
string.bold()
Primary signature.
string.bold(...)
Call with the arguments your case needs.
Built into JavaScript. Call bold(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
string.bold()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
HTML string with <b> tags
JavaScript Examples
Example 1 — Basic Wrap
Call bold() to build the classic <b> HTML string.
JavaScript
const text = "Hello, world";
console.log(text.bold());
// "<b>Hello, world</b>"
Empty input."".bold() still wraps tags around nothing → "<b></b>".
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 bold() into innerHTML.
Example 3 — Prefer DOM / <strong>
Compare the legacy wrapper with a modern, semantic approach.
JavaScript
// Legacy — do not use in new code
console.log("Important".bold());
// "<b>Important</b>"
// Prefer DOM + semantic emphasis
const el = document.createElement("strong");
el.textContent = "Important";
console.log(el.outerHTML);
// "<strong>Important</strong>"
Legacy path."Important".bold() builds a <b> HTML string.
Create a real element.createElement("strong") marks strong importance.
Set plain text.textContent is safer than injecting markup strings.
Rule of thumb. Learn bold() to read old code; ship DOM or CSS for new UI.
Compatibility
Browser & Runtime Support
String.prototype.bold() is still implemented widely for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.prototype.bold()
Available in major browsers and Node.js for legacy compatibility. Prefer DOM APIs, CSS font-weight, or <strong> 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
bold()Avoid in new code
Bottom line: Recognize bold() when reading old code. For new UI, create elements with textContent, use CSS font-weight, or semantic <strong> — never build markup with string wrappers.
Frequently Asked Questions
bold() returns a new HTML string that wraps the text in a <b> element — for example "Hello".bold() returns "<b>Hello</b>". 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-weight, or a semantic <strong> element when the text is important.
Yes. Unlike <blink> or <big>, <b> is still in HTML. Use it to draw attention without extra importance. Use <strong> when the text has strong importance, or CSS font-weight for visual weight alone.
No. Strings are immutable. bold() returns a new string containing markup; the original text stays the same.
Use document.createElement("b") or createElement("strong"), set textContent, and append the element. Or apply CSS font-weight without building HTML strings.
No. Characters like < and > are left as-is inside the wrapper. Never pass untrusted user input through bold() into innerHTML.