How do you define a base URL for all relative URLs in a document?
To define the base URL of all relative URLs in HTML documents, use the <base> element in
; 1. Place the <base> tag in and set the base URL through the href attribute, such as
) will be parsed based on the base, such as loading https://example.com/images/photo.jpg; 5. Once set, it will affect all relative links in the document and be set with caution. 
To define a base URL for all relative URLs in an HTML document, you use the <base> element in the section of the document.

The <base> tag specifies the base URL and/or base target for all relative URLs used in the page. You can set it like this:
<head> <base href="https://www.example.com/path/" target="_blank"> </head>
Key Points:
- The
hrefattribute sets the base URL for all relative links (like<a>,<img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/175540164663803.jpeg" class="lazy" alt="How do you define a base URL for all relative URLs in a document?" >,<link>,<script>, etc.). - The
targetattribute (optional) defines the default opening context for links (eg,_blank,_self,_parent,_top). - Only one
<base>element is allowed per document. - All relative URLs in the document will be resolved relative to the base URL.
Example:
With this base:

<base href="https://example.com/images/">
Then this image tag:
<img src="/static/imghw/default1.png" data-src="photo.jpg" class="lazy" alt="How do you define a base URL for all relative URLs in a document?" >
...will load the image from https://example.com/images/photo.jpg .

Similarly, a link like:
<a href="about.html">About</a>
...will point to https://example.com/images/about.html (unless the base path is overridden by server routing or other mechanisms).
⚠️ Important: Once set, the base URL affects all relative URLs in the document, so choose it carefully.
Basically, just place the <base> tag in the with the desired href , and the browser will resolve all relative URLs from that point onward.
The above is the detailed content of How do you define a base URL for all relative URLs in a document?. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20524
7
13634
4




