DOM Properties
HTMLAnchorElement.href
Read/write. Returns the serialized resolved URL when the href attribute is valid; if missing it returns an empty string. The attribute getter instead returns the original authored text or null. Validate allowed URL schemes for user-generated destinations. Example result: https://example.com/docs/intro.
Formal Syntax & Structure
html syntaxhtml
element.hrefReturn Value
string
Property value. Read/write.
Working Example
Example Snippethtml
<base href="https://example.com/docs/"><a id="demo" href="intro">Intro</a><p> Result: <output id="result"></output></p><script> const e = document.getElementById('demo'); const result = value => { document.getElementById("result").textContent = String(value); }; result(e.href);</script>