String.prototype.bold() is a deprecated HTML wrapper method (same API as MDN String.prototype.bold()). It returns a string that wraps your text in a <b> tag. Learn what it builds, how <b> differs from <strong>, 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-weight
Fundamentals
Introduction
Early JavaScript included helpers that wrapped text in HTML presentation tags — bold(), big(), blink(), italics(), and others. They made it easy to inject markup with innerHTML.
Today those wrappers are deprecated. bold() may still return a string for compatibility. The <b> element remains valid HTML, but you should create it with the DOM (or use CSS / <strong>) — not string methods.
💡
Learn it, don’t ship it
Study bold() so you can recognize legacy code. For new pages, create real elements with document.createElement() or apply font-weight instead of building <b> strings.
You get a live element you can style, attach listeners to, and keep separate from untrusted HTML concatenation. Use <strong> when the meaning is important, or CSS font-weight for look only.
Applications
🚀 Common Use Cases
Reading legacy tutorials — recognize HTML wrapper methods in old samples.
Migrating old scripts — replace bold() with createElement() or CSS font-weight.
Teaching string immutability — show that methods return new strings.
Not for new apps — do not use bold() to build HTML in new apps.
Semantic emphasis — prefer <strong> for importance and CSS for look-only weight.
Safer markup — prefer textContent + CSS over innerHTML strings.
🧠 How bold() Builds Markup
1
Start with text
You call str.bold() on a string receiver.
Input
2
Wrap with tags
Concatenate <b> + text + </b>.
Wrap
3
Return an HTML string
No DOM node is created — only text markup.
Result
4
⚠️
Prefer the DOM
Create a real <b> or <strong> element with the DOM.
Important
📝 Notes
bold() is deprecated — standardized only for compatibility.
The method is deprecated; the <b> element itself remains valid HTML.
<b> draws attention; <strong> marks strong importance — pick the right one.
It returns a string, not a DOM node.
It takes no parameters.
Other HTML wrappers (big(), blink(), italics(), …) share the same fate.
Avoid assigning untrusted strings to innerHTML.
Compatibility
Browser & Runtime Support
String.prototype.bold() is still widely implemented for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.bold()
Available in modern browsers for old code, but MDN recommends DOM APIs such as createElement() instead.
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() in legacy samples. For new UI, create elements with the DOM or use CSS font-weight — never rely on HTML wrapper string methods.
Wrap Up
Conclusion
String.prototype.bold() builds a <b>...</b> HTML string. The method is deprecated — useful for history and migrating old code — not for writing new features.
Use document.createElement("b") or CSS font-weight
Use <strong> when the text is important
Prefer textContent over string-built HTML
Replace bold() when you touch legacy files
Learn wrappers only to recognize deprecated APIs
❌ Don’t
Use bold() in new production code
Assume string-built HTML is the best way to bold text
Inject untrusted bold() output via innerHTML
Expect bold() to return a live element
Mix HTML wrappers with modern component frameworks
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about String.bold()
Deprecated HTML wrapper — prefer createElement or CSS.
5
Core concepts
📝01
Returns
HTML string
API
⚠️02
Status
deprecated
Legacy
✅03
Markup
<b> OK
HTML
✓04
Replace
createElement
Modern
⚡05
Mutates
no
Immutable
❓ Frequently Asked Questions
String.prototype.bold() returns an HTML string that wraps the text in a <b> element — for example "Hello".bold() returns '<b>Hello</b>'. It takes no parameters.
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 HTML 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.
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 <b> and <strong>. Use <b> for stylistic attention without changing importance, and <strong> when the meaning is strongly important. CSS font-weight covers look-only bolding.