base tag in html with examples
- The <base> tag specifies the base URL/target for all relative URLs in a document.
- 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.
- Only one <base> element may exist in the header and the base element is not required to exist in the header.
- The HTML <base> element must occur before any other elements with partial URIs if the base element exists in the header.
Example 1 :
<html>
<head><title>Paragraph</title>
<base href="http://20fingers2brains.blogspot.in/" target="_blank" />
</head>
<body>
<a href="">20 fingers 2 brains</a>
</body>
</html>
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.
0 comments:
Post a Comment