Computer Study

Base Tag in HTML

The <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.

Syntax:

<head>
<base href=”base_url”>
</head>

The 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:

<!DOCTYPE html>
<html>
<head>
<base href=”https://www.example.com/”>
<title>My Web Page</title>
</head>
<body>
<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″>
</body>
</html>

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.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button