Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <base> id Attribute

An id on a <base> tag assigns an identifier to the element.

The identifier must be unique across the page.

Example

#

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>

Using id

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.


Syntax

<base id="identifier" />

Values

#

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 (.).

More Examples

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>

Code explanation

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.


Browser support

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

You may also like

 Back to <base>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides