Table of Contents
1. Build the basic document structure
1. DOCTYPE element
2. Other elements
2. Use metadata elements to describe documents
1. Set the document title: title element
2. Set the parsing base for relative URLs
3. Use metadata to describe the document
三、使用脚本元素
Home Web Front-end H5 Tutorial A detailed introduction to HTML5-creating HTML documents

A detailed introduction to HTML5-creating HTML documents

Mar 11, 2017 pm 04:52 PM

One of the major changes in HTML5 is: Separating the semantics of an element from the impact of the element on the rendering results of its content. In principle, this makes sense. HTML elements are responsible for the structure and meaning of the document content, and the presentation of the content is controlled by CSS styles applied to the elements. The following introduces the most basic HTML elements: document elements and metadata elements.

1. Build the basic document structure

There are only 4 document elements: DOCTYPE element, html element, head element, and body element.

1. DOCTYPE element

Every HTML document must start with a DOCTYPE element. It tells the browser two things: first, that it is dealing with an HTML document; and second, the version of HTML used to mark up the document's content.
Note, the DTD required in HTML4 is no longer used in HTML5!

  • If the web page code contains the DOCTYPE element, the browser will parse it according to the standards you declare;

  • If you do not add the DOCTYPE element, the browser will Put the web page into quirks mode, there will be a certain difference between the two! !

<!-- HTML4 --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
            <!-- HTML5 --><!DOCTYPE HTML>
Copy after login

2. Other elements

<!DOCTYPE HTML><html>
    <head>
        <title>title</title>
    </head>
    <body>
        文档内容    </body></html>
Copy after login

It should be noted that there must be a title element in the head element!

2. Use metadata elements to describe documents

Metadata elements should be placed in the head element.

1. Set the document title: title element

2. Set the parsing base for relative URLs

The base element can be used to set a base URL for relative links in HTML documents Analyze on this basis. The base element also sets how the link opens when the user clicks it, and how the browser reacts when the form is submitted (described in Chapter 12, Forms).

<!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Base Test</title>
    <!-- 指定相对URL的基准URL -->
    <base href="http://avatar.csdn.net">
    <!-- 指定链接打开方式为:当前页面 -->
    <base target="_self"></head><body>
    <!-- 图片地址:http://www.php.cn/ -->
    <img src="/static/imghw/default1.png"  data-src="/1/4/A/1_ligang2585116.jpg"  class="lazy"   alt="奋飞">
    <a href="http://http://www.php.cn/">PHP中文网</a></body></html>
Copy after login

Note: If you do not specify a base URL, the browser will identify the URL of the current document as the parsing base for all relative URLs.

3. Use metadata to describe the document

The meta element can be used to define various metadata of the document; each meta element can only be used for one purpose.
(1) Specify the name/value metadata pair
You need to use its name and content attributes. 5 predefined metadata names are provided.

##application nameThe name of the web application system to which the current page belongsauthorThe author name of the current pagedescriptionDescription of the current pagegeneratorThe name of the software used to generate HTMLkeywordsA batch of comma-separated strings used to describe the content of the page
Metadata nameDescription

Description: Tell the browser how to classify and grade the content, In the past, the main method was to use keywords metadata. It is now devalued due to its misuse to create the illusion of page content and relevance. (2) Meta is widely used

<!-- 文档内容的字符编码 -->
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html charset=UTF-8">
<!-- 5s后刷新当前页面 -->
<meta http-equiv="refresh" content="5">
<!-- 5s后跳转到MyBlog -->
<meta http-equiv="refresh" content="5; http://www.php.cn/">
Copy after login

4. Define CSS styles

The style element is used to define the CSS style embedded in the HTML document, and the link element is used to import the CSS style in the external style sheet. style.

(1) Specify the media to which the style applies

media attribute can be used to indicate under what circumstances the document should use the style defined in this element.

DeviceDescription##all##auralSpeech synthesizerbrailleBraille devicehandheldHandheld deviceprojectionProjector printPrint preview and print page#screenComputer monitor screenttyMonowidth equipment such as teletypewriterstvTV set
<!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Style Test</title>
    <!-- 显示样式 && 小于500px -->
    <style media="screen and (max-width:500px)">
        p{            
        background-color: blue;            
        color: white;        }
    </style>
    <!-- 显示样式 && 大于500px -->
    <style media="screen and (min-width:500px)">
        p{            background-color: grey;            color: white;        }
    </style>
    <!-- 打印样式 -->
    <style media="print">
        p{            background-color: green;            font-weight: bold;        }
    </style></head><body>
    <p>
        注意我的背影颜色吼!!!    </p></body></html>
Copy after login
All devices (Default)

It should be noted that A detailed introduction to HTML5-creating HTML documents, when using the above media attributes, you need to conduct comprehensive testing and prepare unavailable backup styles.
(2) Specify external resources The link tag also supports the media attribute. Among them, the ref attribute determines how the browser treats the link element.

ValueDescription##authorDocument author Help document for the current documentIcon resourceRelated license for the current documentLoad external style sheet
#help
icon
license
stylesheet
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Link Test</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /></head><body></body></html>
Copy after login

注意:如果网站标志文件位于项目根目录下,就无需使用link元素加载,其会自动请求加载该文件。

三、使用脚本元素

与脚本相关的有两个元素:第一个是script,定义脚本并控制其执行过程;第二个是noscript,规定浏览器不支持脚本或禁用脚本情况的处理方法。
在引入外部资源时,如果使用自闭合标签,浏览器会忽略这个元素,不会加载引用的文件。
其加载资源时,可以使用async(script元素默认行为是在加载和执行脚本同时暂停处理页面,该属性可以让资源异步加载)和defer(告知浏览器等页面载入和解析完毕后才能执行脚本)控制。【JavaScript异步编程设计快速响应的网络应用】

<!-- 未启用或不支持脚本 --><noscript>
    <!-- 5s后跳转到http://www.php.cn/ -->
    <meta http-equiv="refresh" content="5; http://www.php.cn/"></noscript>
Copy after login

The above is the detailed content of A detailed introduction to HTML5-creating HTML documents. 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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

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

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

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

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

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

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

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

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

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

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

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

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

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

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles