4 min read
ā¢Question 49 of 49mediumWhat is the Base Element?
Setting default URL for links.
What You'll Learn
- Using the base element
- Setting base URL
- Default link target
The Base Element
The <base> element sets the base URL for all relative URLs in the document. It can also set the default target for links.
Example
index.htmlHTML
<head>
<base href="https://example.com/app/">
</head>
<body>
<!-- Links to https://example.com/app/about -->
<a href="about">About</a>
<!-- Loads https://example.com/app/images/logo.png -->
<img src="images/logo.png" alt="Logo">
<!-- Absolute URLs still work normally -->
<a href="https://other-site.com">External</a>
</body>With Default Target
index.htmlHTML
<base href="https://example.com/" target="_blank">
<!-- All links open in new tab by default -->Important Notes
- Only ONE base element per document
- Place early in
<head>before any URLs - Affects ALL relative URLs on the page