Home Web Front-end Front-end Q&A What is the usage of base in html5

What is the usage of base in html5

Feb 03, 2023 am 10:13 AM
html5 base

The function of the base tag in html5 is to specify the default URL or default target for all relative links on the page. In a document, up to one <base> element can be used, and it must be located in <head> Inside the element, its usage is as follows: "<head><meta charset="utf-8"> <title></title><base href="..." target="_blank"> </head>”.

What is the usage of base in html5

The operating environment of this tutorial: Windows 10 system, HTML5 version, DELL G3 computer

What is the usage of base in html5? The

<base> tag specifies the default URL or default target for all relative links on the page.

In a document, at most one <base> element can be used. The <base> tag must be inside the <head> element.

Tip: Please place the <base> tag as the first element in the <head> element, so that other elements in the head area can use the information in the <base> element.

Note: If the <base> tag is used, it must have the href attribute or the target attribute or both attributes.

Example

Specify the default URL and default target of all links on the page:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt; 
&lt;title&gt;&lt;/title&gt;
&lt;base href=&quot;//www.w3cschool.cn/statics/images/w3c/&quot; target=&quot;_blank&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;&lt;img src=&quot;logo.png&quot; &gt; - 注意这里我们设置了图片的相对地址。能正常显示是因为我们在 head 部分设置了 base 标签,该标签指定了页面上所有链接的默认 URL,所以该图片的访问地址为 &quot;https://www.w3cschool.cn/statics/images/w3c/logo.png&quot;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;logo.png&quot;&gt;w3cschool logo&lt;/a&gt; - 注意这个链接会在新窗口打开,即便它没有 target=&quot;_blank&quot; 属性。因为在 base 标签里我们已经设置了 target 属性的值为 &quot;_blank&quot;。&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy after login

Recommended learning: "HTML Video Tutorial

The above is the detailed content of What is the usage of base in html5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

Nested Table in HTML

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Table Border in HTML

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

HTML margin-left

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Moving Text in HTML

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

HTML Ordered List

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

HTML onclick Button

Base Dawgz ($DAWGZ) multichain token launched on decentralized exchanges today Base Dawgz ($DAWGZ) multichain token launched on decentralized exchanges today Sep 06, 2024 am 06:34 AM

Base Dawgz ($DAWGZ) multichain token launched on decentralized exchanges today

See all articles