String.prototype.link(url) is a legacy HTML wrapper that returns a new string wrapping your text in <a href="…">…</a>. It 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.link. Start with this line.
JavaScript
string.link(url)
Call
What it does
string.link(url)
Primary signature.
string.link(...)
Call with the arguments your case needs.
Built into JavaScript. Call link(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
string.link(url)
Parameters
Parameter
Description
url
Required. Value for the href attribute
Return Value
Return Value
Description
*
HTML string with <a href> tags
JavaScript Examples
Example 1 — Basic Wrap
Call link(url) to build the classic <a href> HTML string.
JavaScript
const text = "MDN Web Docs";
const url = "https://developer.mozilla.org/";
console.log(text.link(url));
// '<a href="https://developer.mozilla.org/">MDN Web Docs</a>'
Escape quotes. A " inside url becomes " in the markup text.
Empty label. Tags are still produced; content between them is empty.
Type is string. You get text, not a DOM node you can click yet.
Ampersands.& is not auto-escaped — write & when the URL needs it.
Example 3 — Prefer the DOM Instead
Compare the legacy wrapper with createElement("a").
JavaScript
// Legacy — do not use in new code
console.log("Docs".link("https://example.com"));
// '<a href="https://example.com">Docs</a>'
// Prefer a real element
const el = document.createElement("a");
el.href = "https://example.com";
el.textContent = "Docs";
console.log(el.tagName); // "A"
console.log(el.getAttribute("href")); // "https://example.com"
console.log(el.textContent); // "Docs"
<a href="https://example.com">Docs</a>
A
https://example.com
Docs
How It Works
Legacy path.link() builds an HTML string via the deprecated method.
Create a real element.createElement("a") makes a live node.
Set href and text safely. Assign properties instead of concatenating markup.
Rule of thumb. Learn link() to read old code; ship DOM APIs for new UI.
Compatibility
Browser & Runtime Support
String.prototype.link() is still implemented widely for compatibility, but it is deprecated. Do not use it in new projects.
✓ Deprecated · Legacy
String.prototype.link()
Available in major browsers and Node.js for legacy compatibility. Prefer document.createElement("a") in 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
link()Avoid in new code
Bottom line: Recognize link() when reading old code. For new UI, use createElement("a") with href and textContent — never ship wrapper strings from string methods.
Frequently Asked Questions
link(url) returns an HTML string that wraps the text in an <a> tag with an href attribute — for example "Hello".link("https://example.com") returns '<a href="https://example.com">Hello</a>'.
Yes. MDN marks all HTML wrapper methods as deprecated. Prefer document.createElement("a"), set href and textContent, then append the element.
Yes. Hyperlinks are core HTML. The method is deprecated — not the <a> tag. Build links with the DOM instead of string wrappers.
Yes. Double quotes in url become " so the generated attribute stays well-formed as HTML text. Ampersands (&) are not auto-escaped — use & when needed.
No. Strings are immutable. link() returns a new string containing HTML markup. The original text stays the same.
Use document.createElement("a"), set elem.href and elem.textContent, then appendChild. Avoid building links with innerHTML from untrusted strings.