Learn HTML and Master the Fundamentals of Web Development

HTML Base Tag

The <base> tag in HTML is used to specify a base URL or target for all relative URLs within a document.

The <base> tag in HTML is used to specify a base URL or target for all relative URLs within a document. It sets the default base URL that is used by web browsers to resolve relative URLs when accessing external resources, such as stylesheets, images, or links.

Here is an example of how the <base> tag is used:

<head>
  <base href="https://www.example.com/" target="_blank">
</head>

In this example, the <base> tag is placed within the <head> section of the HTML document. The href attribute specifies the base URL, which is set to “https://www.example.com/“. This means that all relative URLs in the document will be resolved relative to this base URL.

The target attribute specifies the default target for all hyperlinks within the document. In the example above, the target attribute is set to “_blank”, which means that when a user clicks on a link, it will open in a new browser tab.

By using the <base> tag, you can provide a consistent base URL for all relative URLs in your document, simplifying resource references and ensuring correct navigation. It is particularly useful when working with complex directory structures or when you want to open links in a specific target.

It’s important to note that the <base> tag should be used carefully, as it affects the entire document. It is typically placed within the <head> section and should appear before any other elements that depend on the base URL.

In summary, the <base> tag in HTML allows you to set a base URL and default target for all relative URLs within a document. It provides a convenient way to ensure consistent resource resolution and link behavior throughout your web page.