base tag in html with examples

  1. The <base> tag specifies the base URL/target for all relative URLs in a document.
  2. The <base> tag goes inside the <head> element. The HTML <base> element has no ending tag. The HTML <base> element supports the TARGET attribute in frame and transitional document type definitions. 
  3. Only one <base> element may exist in the header and the base element is not required to exist in the header.
  4. The HTML <base> element must occur before any other elements with partial URIs if the base element exists in the header.

 Example 1 :

    <base href="" target="_blank" />
<a href="">20 fingers 2 brains</a>

Demo :

In the above example we have shown how base tag works. We have defined a base url in the head section. We have created one anchor element, and its href attribute is set to nothing. But still when you click on the link it directs to the blog. This is because, when you declare base url in the head section, it uses it as a default url for entire document. The scenario where href attribute is not set to url, base url is referred. In other cases, you will be directed to the url specified in respective anchor element.


Post a Comment