String HTML methods (bold, italics, link…)
Netscape shipped these in 1995 and the web never let them go. They are normatively optional, they generate tags that HTML5 removed, and they interpolate without escaping. Documented here so you recognise them — not so you use them.
Demo
bold() stands in for the whole family — every one of the thirteen does the same thing with a different tag name. The third case is the reason this page exists as a warning rather than a recommendation: the input is dropped into the output verbatim, so anything that looks like markup stays markup. Wrapping user input this way and inserting the result with innerHTML is a textbook XSS hole, and the tag it produces was removed from HTML5 anyway.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | string | no (none) | Only four of the thirteen take an argument: link(url), anchor(name), fontcolor(color) and fontsize(size). The value is inserted into the attribute with quotes escaped but nothing else. |
Return value
string — The string wrapped in an HTML tag. No escaping is performed on the text OR on the attribute values, which is why these are unsafe as well as obsolete.
Common patterns
el.style.fontWeight = "bold";
const a = document.createElement("a"); a.href = url; a.textContent = label;
const html = `<strong>${escapeHtml(text)}</strong>`;
Examples
Pitfalls
'<img src=x onerror=alert(1)>'.bold()
el.textContent = userInput;
'hi'.fontsize(7)
el.style.fontSize = "2em";
'hi'.bold()
`<strong>${escapeHtml(s)}</strong>`
'click'.link('javascript:alert(1)')
new URL(u).protocol === 'https:'
When to use
- Never in new code
- Recognising them while reading something written long ago
- Styling text → CSS
- Building markup → createElement with textContent, or a templating layer that escapes
- Anything involving user input → these escape nothing
- Portable code → Annex B is optional outside browsers
Notes
FAQ
Thirteen: anchor, big, blink, bold, fixed, fontcolor, fontsize, italics, link, small, strike, sub and sup. Four take an argument — anchor, link, fontcolor and fontsize — and the rest simply wrap.
'x'.bold(); // '<b>x</b>' 'x'.sub(); // '<sub>x</sub>' 'x'.link('/y'); // '<a href="/y">x</a>'