The HTML Tag: base is used to specify the base URL for all the relative URLs in a document. It is an essential tag that helps in defining the base URL for all the links and resources used in a web page. The base URL is used as a reference point for all the relative URLs in the document. This tag is usually placed in the head section of an HTML document.
The HTML Tag: base is used to specify the base URL for all the relative URLs in a document. It is an essential tag that helps in defining the base URL for all the links and resources used in a web page. The base URL is used as a reference point for all the relative URLs in the document. This tag is usually placed in the head section of an HTML document.
The base tag has only one attribute, which is href. The href attribute specifies the base URL for all the relative URLs in the document. The value of the href attribute should be an absolute URL. If the href attribute is not specified, the base URL is assumed to be the URL of the current document.
Example 1: Setting the base URL for a web page
<!DOCTYPE html>
<html>
<head>
<base href="https://www.example.com/">
</head>
<body>
<a href="about.html">About</a>
<img src="images/logo.png">
</body>
</html>
In the above example, the base URL is set to https://www.example.com/. All the relative URLs in the document will be resolved relative to this base URL. The About link will point to https://www.example.com/about.html, and the logo image will be loaded from https://www.example.com/images/logo.png.
Example 2: Setting the base URL for a web page without the href attribute
<!DOCTYPE html>
<html>
<head>
<base>
</head>
<body>
<a href="about.html">About</a>
<img src="images/logo.png">
</body>
</html>
In the above example, the base URL is not specified using the href attribute. The base URL is assumed to be the URL of the current document. All the relative URLs in the document will be resolved relative to this base URL.