An id on a <base> tag assigns an identifier to the element.
The identifier must be unique across the page.
An id attribute on a <base> element.
<head>
<base href="https://en.wikipedia.org/wiki/" id="page-base">
</head>
<nav>
<a href="Vincent_van_Gogh">Vincent Van Gogh</a> <br />
<a href="Henri_Matisse">Henri Matisse</a> <br />
<a href="Paul_Cézanne">Paul Cézanne</a>
</nav>
The id attribute assigns an identifier to the <base> element.
The identifier must be unique across the page.
The id allows programmatic access to the <base> element.
This gives JavaScript the option to dynamically change the <base> settings.
Tip: id is a global attribute that can be applied to any HTML element.
<base id="identifier" />
Value | Description |
---|---|
identifier | A unique alphanumeric string. The id value must begin with a letter ([base-Zbase-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). |
A <base> tag with a unique id.
Clicking the button will display the href of this base.
<head>
<base id="mybase" href="https://en.wikipedia.org/wiki/" >
</head>
<body>
<nav>
<a href="Vincent_van_Gogh">Vincent Van Gogh</a> <br />
<a href="Henri_Matisse">Henri Matisse</a> <br />
<a href="Paul_Cézanne">Paul Cézanne</a>
</nav><br/><br/>
<button onclick="show();">Show base href</button>
</body>
<script>
let show = () => {
let element = document.getElementById("mybase");
alert("Base href = " + element.href);
}
</script>
The id attribute assigns a unique identifier to the <base> element.
Clicking the button calls JavaScript which locates the <base> using the id.
Once located, the base href value is extracted and displayed.
Here is when id support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <base>