MyInternships.in

HTML Tags

HTML <base> Tag

The <base> tag specifies a base URL and/or default target for all relative URLs in a document. It is a void element placed inside the <head>.


The <base> Tag

The <base> element sets a base URL against which all relative links, images, and other resources on the page are resolved. It can also set a default target for every link and form on the page.

There can be at most one <base> element per document, and it must appear inside <head> before any element that uses a URL. It is a void element, so it has no closing tag.

Syntax

Sets both a base URL and a default link target.
Example
<base href="https://example.com/" target="_blank" />

Example

A relative image path resolved via the base URL.
Example
<!DOCTYPE html>
<html>
  <head>
    <base href="https://picsum.photos/" />
  </head>
  <body>
    <h1>Base URL Demo</h1>
    <img src="200" alt="Random image resolved against the base URL" />
    <p>The relative src "200" resolves to https://picsum.photos/200.</p>
  </body>
</html>

More Examples

Setting a default target of _blank for every link.
Example
<!DOCTYPE html>
<html>
  <head>
    <base target="_blank" />
  </head>
  <body>
    <p>
      <a href="https://www.wikipedia.org/">This link opens in a new tab</a>
      because of the default target set by base.
    </p>
  </body>
</html>

Attributes

AttributeDescription
hrefThe base URL used to resolve all relative URLs in the document.
targetThe default browsing context for links and forms: _self, _blank, _parent, or _top.
⚠️

Use <base> with care. Because it affects every relative URL on the page, including anchors like #section, it can produce surprising behaviour. Most sites use full or root-relative URLs instead.

Key Takeaways

  • <base> sets a base URL for all relative links and resources.
  • It can set a default target for links and forms.
  • At most one <base> is allowed, inside <head>.
  • It is a void element with no closing tag.
  • It must come before any URL-using element in the head.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships