HTML Base Tag | HTML base Tag - Basic syntax of the base tag

HTML <base> Tag:

The `<base>` tag in HTML is used to specify a base URL for all relative URLs within a document. It provides a way to set a default URL for links and forms in a document, helping to establish a consistent base URL for relative paths.

Here is the basic syntax of the `<base>` tag:

html
<head>
  <base href="baseURL">
</head>

- `href`: Specifies the base URL for all relative URLs in the document.

HTML <base> Tag - basic syntax of the base tag
HTML base Tag

Example:


html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- Setting the base URL -->
  <base href="https://example.com/">
  <title>Base Tag Example</title>
</head>
<body>
  <h1>HTML Base Tag Example</h1>
  <!-- Relative URL using the base URL -->
  <a href="page.html">Relative Link</a>
</body>
</html>


In this example, the `<base>` tag is used to set the base URL to "https://example.com/". The link with the `href` attribute set to "page.html" will be resolved relative to this base URL, resulting in the absolute URL "https://example.com/page.html".

It's important to note that the `<base>` tag should be placed within the `<head>` section of the HTML document. If there are multiple `<base>` tags, only the first one is considered. Also, the `href` attribute should include the protocol (e.g., "http://" or "https://") if you want to set an absolute base URL.

Using the `<base>` tag can be helpful in situations where you want to easily change the base URL for all relative links and resources in a document.
ShowHideComments