HTMLLinkElement: href property
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.
Value
A string that contains a URL, or the empty string (""
) if there is no href
element.
Examples
html
<link rel="stylesheet" href="example.css" />
js
const link = document.getElementsByTag("link")[0];
console.log(link.href); // 'example.css'
Specifications
Specification |
---|
HTML Standard # dom-link-href |
Browser compatibility
BCD tables only load in the browser
See also
HTMLLinkElement.imageSrcset
propertyHTMLAnchorElement.href
property