This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The href property of the HTMLLinkElement interface contains a string that is the URL associated with the link.
It reflects the href attribute of the <link> element. If the element does not have an href attribute, then this property's value is the empty string ("").
Note: Every <link> element must contain either one or both of the href or imagesrcset attributes. This means, for each valid <link>, either this property or imageSrcset will not be empty.
A string that contains a URL, or the empty string ("") if there is no href element.
<link rel="stylesheet" href="example.css" />
const link = document.getElementsByTag("link")[0];
console.log(link.href); // 'example.css'
| Specification |
|---|
| HTML> # dom-link-href> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
href |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
HTMLLinkElement.imageSrcset propertyHTMLAnchorElement.href property
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/href