HTML <base> tag
1. Definition: The <base> tag is the base URL tag in the HTML language and is a single tag.
2. Function: Specify the default URL and default target of all links on the page .
E.g:
<!DOCTYPE html> <html lang="en"> <head> <title>base</title> <meta charset="UTF-8"> <base href="http://www.w3cschool.cn" target="_blank"> </head> <body> <p>img标签里的src的绝对路径是http://www.w3cschool.cn/statics/images/course/planets.gif</p> <img src="/statics/images/course/planets.gif" width="145" height="126" alt="Planets"> </body> </html>
Note: base specifies the default URL for all links on the page , yes all! It includes all URLs such as src, href, etc.
The link used will be spliced with the href link in the base.
For example, if the css file cannot be found:
<!DOCTYPE html> <html lang="en"> <head> <title>base</title> <meta charset="UTF-8"> <base href="http://www.w3cschool.cn" target="_blank"> <link rel="stylesheet" type="text/css" href="CSS/first.css" > <!--链接外部资源--> </head> <body> <p> If the external style sheet wants to refer to a file in a directory other than the base link, then the style sheet will not be found. </p> </ body > </ html >
in short:
The base tag has the following rules
- The <base> tag must be inside the <head> element.
- In a document, at most one <base> tag can be used.
- After using the link of the <base> tag, other links must be inside the link of the <base> tag, otherwise it will not be found.