Syntax
The url
worth within the above instance must be changed with absolutely the URL for the doc. Additionally it is attainable to incorporate the goal
attribute, which specifies the default goal for all hyperlinks within the doc. The syntax for that is:
1 |
<base href="url "goal="_blank" /> |
Instance
Right here is an instance of how the <base>
aspect can be utilized in an HTML doc:
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
<base ref="https://instance.com/" /> |
5 |
<title>My Web page</title> |
6 |
</head>
|
7 |
<physique>
|
8 |
<p><a href="about.html">About</a></p> |
9 |
<p><a href="contact.html">Contact</a></p> |
10 |
</physique>
|
11 |
</html>
|
On this instance, the bottom URL for all relative URLs within the doc is about to https://instance.com/
. Subsequently, when a consumer clicks on the About or Contact hyperlinks, they are going to be directed to https://instance.com/about.html
and https://instance.com/contact.html
respectively.
Attributes
The <base>
aspect has two attributes:
-
href
: This attribute specifies the bottom URL for all relative URLs within the doc. -
goal
: This non-obligatory attribute specifies the default goal for all hyperlinks within the doc. Doable values embody_blank
,_self
,_parent
, and_top
.
Content material
The <base>
aspect doesn’t settle for any content material and is a self-closing tag.
Utilization Notes
- If the
<base>
aspect just isn’t current in a doc, the bottom URL is assumed to be the URL of the present doc. - Make sure you add a trailing slash to the URL you’re utilizing, until you’d just like the final a part of the URL to be stripped. For instance:
1 |
<base href="https://www.instance.com/weblog/" /> |
2 |
<img src="picture.png" /> |
3 |
<!-- resolves to https://www.instance.com/weblog/picture.png -->
|
4 |
|
5 |
|
6 |
<base href="https://www.instance.com/weblog" /> |
7 |
<img src="picture.png" /> |
8 |
<!-- resolves to https://www.instance.com/picture.png -->
|
Kezz Bracey goes into extra depth, explaining what we will and may’t do with <base>
in How one can Use the HTML “base” Tag.
Be taught Extra
Do you know? The <base>
aspect was launched in HTML 4.0 in 1998.