DEV Community

Share Point Anchor
Share Point Anchor

Posted on • Originally published at sharepointanchor.com on

HTML <base> Base Tag

In HTML, the Base tag is used to specify a (absolute) base URL or URI for all the relative links. This tag also determines how the link in the current document should be opened.

If you specified any URL with tag, then every other URL on the page prefixed with the specified base URL. The base tag must be defined between the tag.

Note: In HTML the base tag must be included only once in the document, and it must be placed in the element.

You can access the used base URL of a document from scripts with a document.baseURI. Suppose the document doesn’t contain any element, base URL will default to document.location.href.

Estimated reading time: 2 minutes

Syntax:

The tag contains only the open tag in HTML , it does not have the closing tag. But in XHTML the tag must be closed with tag. Do not add any content inside the HTML tag.


<base href="SAMPLE URL">

Enter fullscreen mode Exit fullscreen mode

Note: If you use multiple elements on a page, it will consider the first href and target attribute. Other URLs will be ignored.

Sample of HTML Tag:


<!DOCTYPE html>
<html>
  <head>
    <title>HTML base tag</title>
    <base href="https://www.sharepointanchor.com/" target="_blank">
  </head>
  <body>
<p>HTML</p>
    <img src="https://sharepointanchor.com/wp-content/uploads/2021/02/html.png" alt="" class="wp-image-500"/>
  </body>
</html>

Enter fullscreen mode Exit fullscreen mode

Result:

Attributes:

The tag supports the global attributes and the event attributes. You can use the following properties to style an HTML base tag.

th, td{ padding: 20px; }

Attribute Value Definition
href URL This attribute specifies the base URL for all relative URLs of the page. The default base address is substituted before all relative addresses on the page.
target _blank It helps to open the link in a new window.
_self It is a default. Helps to open the link in the current window.
_parent This attribute value opens the link in the parent frame.
_top It will open the document in the full width of the page.

Browser Support:

Browser Support

Read Also:

The post HTML Base Tag appeared first on Share Point Anchor.

Top comments (0)