- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <base> Tag
HTML Tags
HTML <base> Tag
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 toabout.htmlgoes tohttps://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">| Attribute | What it does |
|---|---|
| href | The base address that relative links are added to. |
| target | The 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
#sectionlinks:href="#top"now points tohttps://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+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
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
