<base> Tag in HTML
The <base> tag in HTML specifies the base URL for all relative URLs in a document. It is typically used in the <head> section to define a reference point for all relative links (like images, hyperlinks, and other resources).
Key Points on <base> Tag:
- The
<base>
tag must be placed inside the<head>
section of the HTML document. - It defines the base URL for all relative URLs in the document.
- It is used to simplify the management of links and resources when the document is placed in different directories or servers.
- The
<base>
tag supports thehref
andtarget
attributes. Thehref
attribute sets the base URL, while thetarget
attribute sets the default browsing context.
Syntax of <base> Tag:
Syntax Example
<base href="https://www.example.com/" target="_blank">
Example of <base> Tag in HTML:
This example demonstrates how to use the <base>
tag to define a base URL for relative links.
Code Example
<html>
<head>
<base href="https://www.example.com/" target="_blank">
</head>
<body>
<a href="{{ url_for('render_dynamic_template', template_name='about') }}">About Us</a>
<a href="{{ url_for('render_dynamic_template', template_name='contact') }}">Contact Us</a>
</body>
</html>
Output
The <base>
tag simplifies the management of relative URLs by setting a base path for all relative links. It is especially useful when the document is referenced from different locations or servers.