<base> tag in HTML is used to specify the base URL or base address for all the links and resources used in the web page. The
<base> tag is usually placed within the
<head> section of an HTML document.
href attribute is used to specify the base URL or base address for all the links and resources in the web page.
Example: Let’s say that we have a web page with multiple links and resources, and the base URL for this page is https://www.example.com/. We can use the
<base> tag to specify the base URL as follows:
<title>My Web Page</title>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph of text.</p>
<a href=”page2.html”>Link to Page 2</a>
<img src=”images/image1.jpg” alt=”Image 1″>
In the above example, the
<base> tag is used to specify the base URL as https://www.example.com/. Now, any links or resources that are referenced in the web page will be relative to this base URL. For example, the link to Page 2 is specified as
page2.html, which means that it will be resolved as https://www.example.com/page2.html. Similarly, the image source is specified as
images/image1.jpg, which means that it will be resolved as https://www.example.com/images/image1.jpg.
In summary, the
<base> tag in HTML is used to specify the base URL or base address for all the links and resources in a web page. This can be helpful in situations where you want to ensure that all links and resources are resolved correctly, even if the page is moved to a different location.