<base>

HTML <base> Tag

The <base> tag has recently become part of HTML5. It defines an absolute (base) URL for all the relative URLs in the HTML document. This tag also determines how links in the current document must be opened (in a new window, in the current window, etc.).

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

Syntax

Syntax (语法)

The <base> tag is empty, which means that the closing tag isn’t required. But in XHTML, the (<base>) tag must be closed (<base/>).

Only one <base> tag can be used on the page, and it must be placed in the <head> element. You must insert it as soon as possible since its action extends from the place where it is specified.

If you use multiple <base> elements, only the first href and target attributes will be obeyed. The rest will be ignored.

Example of the HTML <base> tag:

<!DOCTYPE html>
<html>
 <head>
   <title>HTML base tag</title>
   <base href="https://www.w3cdoc.com/" target="_blank">
 </head>
 <body>
   <a href="/css3-maker/border-radius">Try CSS Maker Tool</a>
 </body>
</html>

Result

In this example, the <base> tag defines the base URL - “https://www.w3cdoc.com/”, and the relative link “/css3-maker/border-radius” will use that URL as a starting point.

Copy the above-mentioned code into our editor, and you will see an active link, which, when clicked, opens in a new window. Although the link itself does not contain the target _blank (将上述代码复制到我们的编辑器中,您将看到一个活动链接,点击后将在新窗口中打开。虽然链接本身不包含target_blank) attribute, it will open in a new window, since we have set the target _blank attribute to the absolute URL in the <base> tag.

Attributes

Attributes (属性)

The <base> tag must necessarily contain either href or target attribute. If necessary, you can use both attributes. (属性。如有必要,您可以使用这两个属性。)

AttributeValueDefinition
hrefURLSpecifies the base URL for all relative URLs of the page. The default base address is substituted before all relative addresses on the page.
target_blankOpens the link in a new window.
_selfOpens the link in the current window.
_parentOpens the link in the parent frame.
_topOpens the document in the full width of the page.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部