Skip to main content

HTML Tags

HTML <base> Tag

Written by Updated HTML <base> Tag exercises

The base tag sets the starting address for every relative link, image and script on the page. Write <base href="https://example.com/"> once in the head, and a link to about.html goes to https://example.com/about.html. Powerful, and easy to break things with.

It goes in the <head>, only once per page, before any other element that uses a link.

Syntax

html

<base href="https://example.com/" target="_blank">
AttributeWhat it does
hrefThe base address that relative links are added to.
targetThe default target for every link and form, like _blank.

Example

html

<!DOCTYPE html>
<html>
<head>
  <title>Base Tag Example</title>
  <base href="https://html5andcss3.org/" target="_blank">
</head>
<body>
  <a href="learn-html/">Learn HTML</a>
  <img src="https://ik.imagekit.io/html5andcss3/browser-icons/chrome.webp" alt="Chrome Logo" width="80">
</body>
</html>

The link "Learn HTML" points to learn-html/, so with the base it goes to https://html5andcss3.org/learn-html/, and it opens in a new tab because of target="_blank". The image uses a full address, so the base does not change it.

Why it is rarely used

  • It changes every relative link, including #section links: href="#top" now points to https://example.com/#top, not to the current page.
  • target="_blank" on every link opens everything in new tabs, which annoys readers.
  • Moving the site to another domain silently breaks every link.

Most sites use root-relative links like /about/ instead, which work without <base>. More about link addresses and other hyperlinks details are in HTML Links.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML <base> Tag exercises

Set a base address

Write the one line that makes relative links on a page start from https://example.com/docs/

Result

Check your answer to see it here.