", which is a document type declaration of a standard universal markup language; 2. "", which is used to inform the browser that it is an HTML document; 3. "" contains the metadata of the document; 4. "" contains the content that visitors can see."/> ", which is a document type declaration of a standard universal markup language; 2. "", which is used to inform the browser that it is an HTML document; 3. "" contains the metadata of the document; 4. "" contains the content that visitors can see.">

Home  >  Article  >  Web Front-end  >  What tags must html5 documents have?

What tags must html5 documents have?

青灯夜游
青灯夜游Original
2022-05-18 15:56:506726browse

There must be 4 tags: 1. "", which is a document type declaration of a standard universal markup language; 2. "", which is used to inform the browser of its Itself is an HTML document; 3. "

" contains the metadata of the document; 4. "" is used to contain content that visitors can see.

What tags must html5 documents have?

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

html5 document must have 4 tags

  • ##

  • ##

  • #

  • HTML document is a description of a document. It has a fixed structure and is divided into many parts. Each part contains one or more elements. Some elements are used to describe the basic information of the document, and some describe the document structure. The following is the structure of a basic HTML document
  • <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>文档标题</title>
    </head>
    
    <body>
    文档内容......
    </body>
    
    </html>
This HTML document describes a blank page. These basic components determine the outline of the HTML document. and the browser's initial environment.

1. tag

DOCTYPE is the abbreviation of document type.

The doctype declaration is a document type declaration in a standard universal markup language. It is used in web design to indicate what version of XHTML or HTML you are using.

It tells the browser two things:

It processes HTML documents;
  • is used to mark document content The version of HTML that is used. The following writing method indicates that HTML5 is used.
  • html5 There is only one doctype declaration:
  • <!DOCTYPE HTML>
The declaration must be located on the first line in the HTML5 document, that is, before the tag . This tag tells the browser the HTML specification used by the document.

Note: The doctype declaration does not belong to the HTML tag, but is a document type tag, which is an instruction.

Explanation:

tag has no closing tag.
  • is not case sensitive.
  • 2. tag

tag is the outermost element in an HTML document. The

tag is a container for all other HTML elements (except the tag).

The function of the root element is to tell the browser that the content between and is of HTML type, and the browser will parse the content as HTML. The

html element has three attributes, namely the lang attribute, the xmlns attribute and the manifest attribute: The

lang attribute specifies the default language used for page content. Specifying the language in which the document is written helps a language synthesis tool choose a pronunciation language, or a translation tool choose translation rules. For example, means that this document is in Chinese.
  • xmlns attribute assigns the XML namespace. The xmlns attribute is required in XHTML but not in HTML.

  • #The manifest attribute gives the URL of the offline cache file. HTML5 introduces application caching, which means web applications can be cached and accessed offline. For example, means that the offline cache file is waibo.manifest.
  • 3. tag

tag is a container for all head tags. These head tags are used to Defining metadata about the HTML document (data that describes the data) and references to the required resources (such as CSS style files, JavaScript script files) play a very important role in enabling the document to be displayed correctly in the browser.

According to our needs, we can define a large amount of metadata in the HTML header, or we can define little or no metadata at all. Although the head tag is part of the HTML document, its content is not displayed in the browser.

4. The

tag

element defines the body of the document. The

element contains all the content of the document, such as text, hyperlinks, images, tables, lists, etc.

Simply put: the body part of the document contains the content that visitors can see.

After having this basic structure, we can gradually add other elements of HTML later, continuously enrich the document, and finally get the page we want.

<body>
	<p>一个段落</p>
	<img  src="img/1.jpg"    style="max-width:90%" / alt="What tags must html5 documents have?" ><br><br>
	<button>一个按钮</button><br><br>
	<input type="text" value="输入框" />
</body>

Note: Only one

tag can exist in an HTML file. What tags must html5 documents have?

Extended knowledge: Elements that can be included in the head tag

##1. tag

标签用来定义 HTML 文档的标题,只有包含 <title> 标签的文档才算是一个有效的 HTML 文档。另外,一个 HTML 文档中仅允许存在一个 <title> 标签,并且 <title> 标签必须放置在 标签中。<p>注意,在 </p> <title> 标签内部仅允许包含纯文本内容,不能包含其他 HTML 标签。<p></p> <title> 标签的主要作用如下所示:<ul style="list-style-type: disc;"> <li><p>在浏览器标题栏或者任务栏中显示标题;</p></li> <li><p>当将页面添加到收藏夹(书签)时提供标题;</p></li> <li><p>在搜索结果中显示页面标题。</p></li> </ul> <p>下面的示例演示了如何在 HTML 文档中使用 </p> <title> 标签:<pre class="brush:html;toolbar:false"><head> <meta charset="utf-8"> <title>php中文网-教程_手册_视频-免费php在线学习平台</title> </head></pre><p></p> <title> 标签的内容必须与当前文档有关,并且不应该过长,中文页面请尽量控制在 30 个字符(包括空格)以内。<p><strong>2、<base> 标签</strong></p> <p><base> 标签用于为页面中所有相对链接指定一个基本链接,当您设置了基本链接后,当前页面中的所有相对链接都会使用这个基本链接作为前缀,如下例所示:</p><pre class="brush:html;toolbar:false"><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title><base>标签演示</title> <base href="https://www.php.cn/"> </head> <body> <ul> <li><a href="course.html">视频教程</a></li> <li><a href="course/type/3.html">入门教程</a></li> </ul> </body> </html></pre><p>上面的示例中第一个 </p> <li> 标签中的超链接会被解析为“https://www.php.cn/course.html”,第二个 </li> <li> 中的超链接会被解析为“https://www.php.cn/course/type/3.html”。<p>注意,HTML 文档中的 <base> 标签必须出现在任何引用外部资源的标签之前,而且一个 HTML 文档中仅允许定义一个 <base> 标签。</p> <p><strong>3、<link> 标签</strong></p> <p><link> 标签经常用于引用外部 CSS 样式表,<link> 标签中包含两个主要的属性,分别是 rel 和 href。rel 属性用来指示引用文件的类型,href 属性用来设置外部文件的路径。示例代码如下:</p><pre class="brush:html;toolbar:false"><head> <title>此处书写标题</title> <link rel="stylesheet" href="common.css"> </head></pre><p>HTML </p> 标签中可以包含任意数量的 <link> 标签。<p><strong>4、<style>标签</style></strong></p> <p>使用 <style> 标签可以在 HTML 文档中嵌入 CSS 样式,需要注意的是在 <style> 标签中定义的样式仅对当前 HTML 文档有效。示例代码如下:</style></p><pre class="brush:html;toolbar:false"><head> <title>此处书写标题</title> <style> body { background-color: YellowGreen; } h1 { color: red; } p { color: green; } </style> </head></pre><p>注意:对于文档中的唯一样式可以使用 <style> 标签,但对于在多个文档中通用的样式,使用外部样式表更为合适。关于在 HTML 中嵌入 CSS 的更多内容,请转到《HTML嵌入CSS样式(四种方法)》。</style></p> <p><strong>5、<meta> 标签</strong></p> <p><meta> 标签用于提供有关 HTML 文档的元数据,例如页面有效期、页面作者、关键字列表、页面描述等信息。<meta> 标签定义的数据并不会显示在页面上,但却会被浏览器解析。</p> <p>1) 定义字符集</p><pre class="brush:html;toolbar:false"><meta charset="UTF-8"></pre><p>charset 属性用来指定 HTML 文档的字符编码,上面的示例中,我们将文档的字符编码设置为了“UTF-8”。</p> <p>2) 定义页面描述</p><pre class="brush:html;toolbar:false"><meta name="description" content="php中文网提供大量免费、原创、高清的php视频教程,并定期举行公益php培训!可边学习边在线修改示例代码,查看执行效果!php从入门到精通,一站式php自学平台!"></pre><p>定义页面的描述信息有利于搜索引擎的搜索。</p> <blockquote> <p></p> <title> 标签定义文档标题,name="description" 定义文档描述,描述的长度通常大于标题。

3) 定义关键字

<meta name="keywords" content="php教程,php入门教程,php视频教程,php源码下载,php手册">

关键字用于为搜索引擎提供与页面有关的信息。

4) 定义页面作者

<meta name="author" content="PHP中文网">

通过某些内容管理系统可以自动提取作者信息。

5) 刷新页面

<meta http-equiv="refresh" content="30">

上例中的代码用于向浏览器发送一个指令,使浏览器在经过指定的时间间隔(30 秒)后自动刷新页面。在 content 属性中除了可以指定时间间隔外,还可以再指定一个链接,这时页面将在指定的时间后重定向到链接所指向的页面,如下例所示:

<meta http-equiv="refresh" content="10; url=https://www.php.cn/">

6、<script> 标签</script>

<script> 标签用于定义 JavaScript 脚本,示例代码如下:</script>

<head>
    <title>PHP中文网</title>
    <script>
        document.write("PHP中文网")
    </script>
</head>

7、

当用户的浏览器不支持 JavaScript 脚本或者禁用 JavaScript 脚本时,可以在

The above is the detailed content of What tags must html5 documents have?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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