What is the base element in HTML?
The base element in HTML is used to specify the URI upon which all the relative URIs in the document are built upon. There can only be one base element in a document.
base must be declared in the <head> tag of the document. If a target is also specified in the base element, that target defaults to the target of the subsequent hyperlinks.
Attributes
href: The URI from which all the subsequent URIs will be resolved.target: The default target for all URIs and forms on the page. Thetargetspecifies how the hyperlinks on the page will open.
Target | Description |
_blank | opens links in a new window |
_parent | links will open in the immediate parent context |
_self | links will open in the same context that's containing the link |
_top | inks will open in the topmost context (the greatest parent context containing the link) |
In the above code, we have set the base URL as https://www.educative.io/ and the target as _blank; this will open the hyperlinks in a new tab. The last <a/> tag contains the URL for the article “How to position an absolutely centered element inside its parent”, but since we are using the base tag, we do not have to include the https://www.educative.io part in its URL.
Free Resources