The HTML5 Specification introduces many new semantic elements, as well as specifications for existing elements; one of which is the <base>
Tag, which allows for specifying a root URL from which all linkable elements in a document (hyperlinks, images etc.) are based, as well as a default target
for all linkable elements.
Overview
- The
<base>
Tag provides two attributes;href
(Hyper-text Reference) andtarget
, respectively, which have the same semantic meaning as that of ahyperlink
. - Only a single
<base>
Tag is to be defined per page and, must be defined before any elements which except aURL
are defined (other than thehtml
element).
Note: While the <base>
Tag is not new to HTML5, the changes to the a
Tag implies a difference (albeit, marginal) as, a
Tags are always hyperlinks, or placeholders for hyperlinks.
Example
Like all HTML markup, usage of the <base>
Tag is easy and straightforward: Simply add a single <base>
Tag in the <head>
element of the document and define either a base URL and / or default target attribute.
Defining a default base URL and target:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html> <html> <head> <base href="http://somedomain/app" target="_blank" /> </head> <body> <nav> <a href="index.php">Home</a> <a href="aboutus.php">About Us</a> <a href="contactus.php">Contact Us</a> </nav> </body> </html> |
The above links will all default to a blank target
(new page), with each link’s base URL defaulting to “http://somedomain/app”. Individual links can override the base URL as well as the default target
.
Support
The <base>
Tag is currently supported by all major browsers.