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> Tag

The <base> tag defines the base URL for all relative links on a page.

Its purpose is to simplify and shorten relative links.

A page can have one <base> tag and must be inside the <head> tag.

Example

#

A <base> tag inside the head tag. All relative URLs start with https://www.company.com/public/.

<head>
  <base href="https://www.company.com/public/">
</head>

Note: The <base> element must be placed before any element with a URL reference, such as <link>.

More Examples

A <base> tag that makes all relative links use the base URL https://en.wikipedia.org/wiki/. Note how it shortens the relative URLs in the HTML.

<head>
  <base href="https://en.wikipedia.org/wiki/">
</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>

Note: The <base> element also shortens the URLs on the src attribute used in image, audio, video, and others.


Attributes for <base>

This table lists the <base> tag attributes.

Attribute Accepted Values Description
href URL Base URL for all relative page URLs
id   identifier Defines a unique identifier for the base.
target _blank
_self
_parent
_top
framename
Defines where or how to open the linked pages

For additional global attributes see our global attributes list.


Page Tags

The <base> tag is part of a group of tags that define the structure of a web page. This group is referred to as the Page tag group. Together, they allow you to create solid, well-structured web pages.

Here is the complete list.

Element Description
<!DOCTYPE> Must appear on the first line of a page. Specifies the HTML version
<html> Defines the root container for an HTML document
<head> Creates a head container that holds page-level metadata elements
<meta> Provides metadata about a web page
<link> Defines a link to an external source, such as a style sheet
<base> Sets the base URL for all relative URLs on a page
<script> Adds JavaScript to a page. Either client- or server-side
<style> Adds CSS style elements to a page
<title> Specifies the page title that displays in the browser's tab
<body> Specifies a container for the content of the page, with text, links, images, etc.

Browser support

Here is when <base> 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


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