1. Introduction to <base> tag in HTML.
2. Syntax of <base> tag in HTML.
Introduction of <base> Tag in HTML
The HTML <base> tag specifies the base URL for all the URLs in an HTML document. After this, you don't need to enter the full URL. Whenever you add a URL, the base URL is automatically prefixed before that URL.
For example, suppose your images are in the webImage/images directory, which address C:/Users/AYAN/Desktop/documents/web-images/images. Whenever you add an image, you have to define the full address as below.
<img src = C:/Users/AYAN/Desktop/documents/webImage/images/showcase.jpg">
Similarly, for all of the images you want to add, you will have to specify the full address. But if you define the address of the web-files directory as a base URL, then you will not have to type the full URL to add images. You can see as below.
<img src = "showcase.jpg">
All the links specified in the document will be related to the base URL. Base URL is defined at the top of the page and you can use the rest of the links in short forms.
The code is reduced in the document by using the <base> tag. It also makes the code easier to understand.
The main drawback of the <base> tag is that once you define it you are bounded because all links before it automatically get prefix. It is not possible to do so if you want to add an image or file from another location.
The <base> tag is also included in HTML5. By this, you define the base URL for all the URLs and you can also set the target for all the links.
The <base> tag is also included in HTML5. By this, you define the base URL for all the URLs and you can also set the target for all the links.
How to use the base tag in HTML?
Syntax of <base> Tag in HTML
The general syntax of the lower <base> tag is given as below.
<base href = "base-url" target = "_ blank">
It is necessary to define either a href or the target attribute in a <base> tag. <base> can’t be defined without the attribute.
There is no end tag of the <base> tag in HTML. This is an empty tag. But if you are using it in XHTML, it must be closed by the </ base> end tag.
The <base> tag should be only defined once in the entire document. It should always be defined within the <head> tag.
Attributes of <base> Tag in HTML
There are two attributes available with <base> tag. These are described as below.
href
This attribute specifies the base URL. The URL is written in double quotes.target
By this attribute, you can define the target of links. The values of this attribute can be defined as below.
_blank
When you want to open the link in a new window, you will have to define target as "_blank".
When you want to open the link in a new window, you will have to define target as "_blank".
_self
When you want to open the link in the current window, you will have to define target as "_self".
When you want to open the link in the current window, you will have to define target as "_self".
_parent
When you want to open the link in the parent container, the target should be "_parent".
When you want to open the link in the parent container, the target should be "_parent".
HTML also supports global and event attributes in <base> tag.
Example of HTML <base> Tag which is given as below.


0 Comments:
Post a Comment
Thank you for reading this post. Please do not enter any spam link in the comment box.