1.新的文檔類(lèi)型 (New Doctype)
目前許多網(wǎng)頁(yè)還在使用XHTML 1.0 并且要在第一行像這樣聲明文檔類(lèi)型:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
在HTML5中,上面那種聲明方式將失效。下面是HTML5中的聲明方式:
<!DOCTYPE html>
2.腳本和鏈接無(wú)需type
(No More Types for Scripts and Links)在HTML4或XHTML中,你需要用下面的幾行代碼來(lái)給你的網(wǎng)頁(yè)添加CSS和JavaScript文件。
<link rel="stylesheet" href="style/stylesheet.css" type="text/css" /> <script type="text/javascript" src="js/script.js"></script>
而在HTML5中,你不再需要指定類(lèi)型屬性。因此,代碼可以簡(jiǎn)化如下:
<link rel="stylesheet" href="style/stylesheet.css" /> <script src="js/script.js"></script>
3.語(yǔ)義Header和Footer (The Semantic Header and Footer)
在HTML4或XHTML中,你需要用下面的代碼來(lái)聲明"Header"和"Footer"。
<div id="header"></div> <div id="footer"></div>
在HTML5中,有兩個(gè)可以替代上述聲明的元素,這可以使代碼更簡(jiǎn)潔。
<header></header> <footer></footer>
4.Hgroup
在HTML5中,有許多新引入的元素,hgroup就是其中之一。假設(shè)我的網(wǎng)站名下面緊跟著一個(gè)子標(biāo)題,我可以用
和標(biāo)簽來(lái)分別定義。然而,這種定義沒(méi)有說(shuō)明這兩者之間的關(guān)系。而且,h2標(biāo)簽的使用會(huì)帶來(lái)更多問(wèn)題,比如該頁(yè)面上還有其他標(biāo)題的時(shí)候。在HTML5中,我們可以用hgroup元素來(lái)將它們分組,這樣就不會(huì)影響文件的大綱。<header>
<hgroup>
<h1> Recall Fan Page </h1>
<h2> Only for people who want the memory of a lifetime. </h2>
</hgroup>
</header>
<header> <hgroup> <h1> Recall Fan Page </h1> <h2> Only for people who want the memory of a lifetime. </h2> </hgroup> </header>
5.標(biāo)記元素 (Mark Element)
你可以把它當(dāng)做高亮標(biāo)簽。被這個(gè)標(biāo)簽修飾的字符串應(yīng)當(dāng)和用戶當(dāng)前的行動(dòng)相關(guān)。比如說(shuō),當(dāng)我在某博客中搜索“Open your Mind”時(shí),我可以利用一些JavaScript將出現(xiàn)的詞組用修飾一下。
<h3> Search Results </h3> <p> They were interrupted, just after Quato said, <mark>"Open your Mind"</mark> </p>
6.圖形元素 (Figure Element)
在HTML4或XHTML中,下面的這些代碼被用來(lái)修飾圖片的注釋。
<img src="/static/imghw/default1.png" data-src="image/image" class="lazy" alt="HTML5 new features" /> <p>Image of Mars </p>
然而,上述代碼沒(méi)有將文字和圖片內(nèi)在聯(lián)系起來(lái)。因此,HTML5引入了
<figure> <img src="/static/imghw/default1.png" data-src="path/to/image" class="lazy" alt="HTML5 new features" /> <figcaption> <p>This is an image of something interesting.</p> </figcaption> </figure>
7.重新定義small (Small Element redefined)
在HTML4或XHTML中,small元素已經(jīng)存在。然而,卻沒(méi)有如何正確使用這一元素的完整說(shuō)明。在HTML5中,small被用來(lái)定義小字。試想下你網(wǎng)站底部的版權(quán)狀態(tài),根據(jù)對(duì)此元素新的HTML5定義,small可以正確地詮釋這些信息。
8.占位符 (Placeholder)
在HTML4或XHTML中,你需要用JavaScript來(lái)給文本框添加占位符。比如,你可以提前設(shè)置好一些信息,當(dāng)用戶開(kāi)始輸入時(shí),文本框中的文字就消失。
而在HTML5中,新的“placeholder”就簡(jiǎn)化了這個(gè)問(wèn)題。
9.必要屬性 (Required Attribute)
HTML5中的新屬性“required”指定了某一輸入是否必需。有兩種方法聲明這一屬性。
<input type="text" name="someInput" required> <input type="text" name="someInput" required="required">
當(dāng)文本框被指定必需時(shí),如果空白的話表格就不能提交。下面是一個(gè)如何使用的例子。
<form method="post" action=""> <label for="someInput"> Your Name: </label> <input type="text" id="someInput" name="someInput" placeholder="Douglas Quaid" required> <button type="submit">Go</button> </form>
在上面那個(gè)例子中,如果輸入內(nèi)容空且表格被提交,輸入框?qū)⒈桓吡溜@示。
10.Autofocus 屬性 (Autofocus Attribute)
同樣,HTML5的解決方案消除了對(duì)JavaScript的需要。如果一個(gè)特定的輸入應(yīng)該是“選擇”或聚焦,默認(rèn)情況下,我們現(xiàn)在可以利用自動(dòng)聚焦屬性。
<input type="text" name="someInput" placeholder="Douglas Quaid" required autofocus>
11.Audio 支持 (Audio Support)
目前我們需要依靠第三方插件來(lái)渲染音頻。然而在HTML5中,
<audio autoplay="autoplay" controls="controls"> <source src="file.ogg" /> <source src="file.mp3" /> <a href="file.mp3">Download this file.</a> </audio>
當(dāng)使用
12.Video 支持 (Video Support)
HTML5中不僅有
<video controls preload> <source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" /> <source src="cohagenPhoneCall.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" /> <p> Your browser is old. <.a href="cohagenPhoneCall.mp4">.Download this video instead.</a> </p> </video>
13.視頻預(yù)載 (Preload attribute in Videos element)
當(dāng)用戶訪問(wèn)頁(yè)面時(shí)這一屬性使得視頻得以預(yù)載。為了實(shí)現(xiàn)這個(gè)功能,可以在
<video preload >
14.顯示控制條 (Display Controls)
如果你使用過(guò)上面的每一個(gè)提到的技術(shù)點(diǎn),你可能已經(jīng)注意到,使用上面的代碼,視頻僅僅顯示的是張圖片,沒(méi)有控制條。為了渲染出播放控制條,我們必須在video元素內(nèi)指定controls屬性。
<video preload controls>
15.正規(guī)表達(dá)式 (Regular Expressions)
在HTML4或XHTML中,你需要用一些正規(guī)表達(dá)式來(lái)驗(yàn)證特定的文本。而HTML5中新的pattern屬性讓我們能夠在標(biāo)簽處直接插入一個(gè)正規(guī)表達(dá)式。
<form action="" method="post"> <label for="username">.Create a Username: </label> <input type="text" name="username" id="username" placeholder="4 <> 10" pattern="[A-Za-z]{4,10}" autofocus required> <button type="submit">.Go </button> </form>
16.Range Input
HTML5引用的range類(lèi)型可以創(chuàng)建滑塊,它接受min, max, step和value屬性 可以使用css的:before和:after來(lái)顯示min和max的值
<input type=”range” name=”range” min=”0″ max=”10″ step=”1″ value=”"> input[type=range]:before { content: attr(min); padding-right: 5px; } input[type=range]:after { content: attr(max); padding-left: 5px;}
新增接口
HTML5為了幫助創(chuàng)建Web App,引入了一些新的接口:
媒體標(biāo)簽video和audio的播放流程控制、同步多個(gè)媒體標(biāo)簽、字幕等接口
表單限制驗(yàn)證接口(如setCustomValidity)
引入應(yīng)用緩存機(jī)制,允許Web App離線的API
允許Web App注冊(cè)為對(duì)應(yīng)協(xié)議或媒體類(lèi)型的處理應(yīng)用的APP的API。(即registerProtocolHandler和registerContentHandler)
引入contenteditable屬性,允許編輯任意元素的接口
暴露會(huì)話歷史、允許使用腳本無(wú)刷新更新頁(yè)面URL(History接口)
base64轉(zhuǎn)換API(atob()及btoa())
處理搜索服務(wù)提供方的接口(AddSearchProvider()及IsSearchProviderInstalled())
External接口
打印文檔的接口(print())(譯注:下列接口是很早就有,屬于BOM中的共識(shí)部分,直到HTML5才加入標(biāo)準(zhǔn))
暴露文檔URL、允許使用腳本切換、刷新頁(yè)面的接口(Location接口)
基于時(shí)間的回調(diào)接口(setTimeout()及setInterval())
提供給用戶的提示接口(alert(),confirm(),prompt())
Window接口
Navigator接口
修改的接口
如下DOM 2的接口已被改動(dòng):
document.title的返回值將會(huì)折疊多個(gè)空格符
document.domain允許賦值,因此可以改變文檔的script origin
document.open()可以清空文檔(如果調(diào)用時(shí)僅有兩個(gè)或以下參數(shù)),或像是window.open()一樣表現(xiàn)(如果調(diào)用時(shí)有三個(gè)或四個(gè)參數(shù))。在前種調(diào)用方式下,拋出一個(gè)XML異常
document.close()、document.write()、document.writeln()拋出一個(gè)XML異常。后兩者允許可變參數(shù),他們可以在文檔解析階段往文檔流中加入文本,并隱式調(diào)用document.open()。在一些情形下,他們都可能會(huì)被忽略
document.getElementsByName()將返回滿足name符合參數(shù)的所有HTML元素
HTMLFormElement的elements接口將返回HTMLFormControlsCollection,包括button, fieldset, input,keygen, object, output, select及textarea
HTMLSelectElement的add()接口允許第二個(gè)參數(shù)為數(shù)字
HTMLSelectElement的remove()接口在參數(shù)越界的時(shí)候,將刪除集合中第一個(gè)元素
在所有的HTML元素中都可以調(diào)用click()、focus()及blur()接口了
a及areastringify為它們的href屬性(譯注:意味著HTMLAnchorElement和HTMLAreaElement對(duì)應(yīng)的toString方法返回它們的href屬性)
Document擴(kuò)展
There is an HTMLDocument interface in DOM Level 2, which inherits from the Document interface and provides an access interface to elements within the document (limited to the HTML category only). HTML5 moves these members into the Document interface and extends it in specific directions. Since all types of documents (Annotation: XML, HTML5, SVG, etc.) use the Document interface, and elements within the HTML5 category are available in all types of documents, these interfaces can work well in documents such as SVG. operation.
In addition, the Document interface has some new members:
location, lastModified and readyState: used to help manage the metadata of the document
dir, head, embeds, plugins, scripts: used to obtain the differences in the DOM tree Part of the
activeElement and hasFocus interfaces are used to determine whether an element has gained focus.
Document editing interface: designMode, execCommand(), queryCommandEnabled(), queryCommandIndeterm(), queryCommandState(), queryCommandSupported(), queryCommandValue()
All IDL event handling properties. In addition, onreadystatechange is the only interface that is valid on Document. The part of the script that modifies the HTMLDocument prototype can still run normally, because window.HTMLDocument will also return the Document interface.
HTMLElement extension
HTMLElement interface has also been extended in HTML5:
Interface dataset for getting data-* attributes
click(), focus(), blur() interfaces allow scripts to simulate user clicks and switching Focus
accessKeyLabel gives UA the shortcut key assigned to the element. Developers can influence the behavior of UA through the accesskey attribute
isContentEditable returns whether the element can be edited
All IDL event processing attributes
Interfaces for getting element attributes such as translate, hidden, tabIndex, accessKey, contentEditable, spellcheck, style (Annotation: DOM Level 2 only recommends using setAttribute and getAttribute on the Element interface to get or set HTML Attribute. These definitions of HTML5 extend the scope of HTML Attribute, allowing them to be like DOM Property is the same as set and get - UA has long been widely supported)
Some interfaces previously defined on HTMLElement have been moved to the Element interface: id, className, classList, getElementsByClassName() (Annotation: Extended the Element interface definition on DOM Level 2 , you can directly set/get attribute values ????such as id - UA has long been widely supported)
Other interface expansion
Other interfaces in DOM Level 2 have also been expanded.
In addition:
HTMLLinkElement and HTMLStyleElement implement the LinkStyle interface in CSSOM
HTMLAnchorElement, HTMLLinkElement and HTMLAreaElement implement the URLUtils interface
Deprecated interface
Attributes that have been deprecated in HTML5, their corresponding IDL attribute interface will also be discarded. If bgColor has been abandoned, then the IDL attribute interface bgcolor on HTMLBodyElement has also been abandoned. For elements that have been abandoned in HTML5, their corresponding interfaces have also been abandoned, including HTMLAppletElement, HTMLFrameSetElement, HTMLFrameElement, HTMLDirectoryElement and HTMLFontElement, HTMLBaseFontElement
Since the HTML parser replaced isindex with other elements, the HTMLIsIndexElement interface was abandoned. Some member attributes were moved from the HTMLDocument interface to the Document interface, so they were abandoned under the original HTMLDocument: anchors and applets.

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.
