Home > Article > Web Front-end > Concise version of HTML5 study notes (1): Introduction and syntax of HTML5
HTML5 Introduction
HTML5 is the next generation of HTML standard specification after HTML4. It provides some new elements and attributes (such as c787b9a589a3ece771e842a6176cf8e9 website navigation block and c37f8231a37e88427e62669260f0074d). The new tags are beneficial to search engines and semantic analysis, and better help small screen devices and visually impaired people use them. In addition, some new features are also provided, such as 39000f942b2545a5315c57fa3276f220 and a8472e34f5fd178af3a76d5495157ae0, in summary, has the following major features:
Cancelled some outdated elements and attribute tags in HTML4
including tags for purely display effects, such as 240cb830ca84ebaabbd07850110b414d and bacbf9e1ad7f40415ce1670e31edfee3, they have been replaced by CSS. HTML5 has absorbed some suggestions from XHTML2, including some features to improve document structure. For example, the use of new HTML tags header, footer, dialog, aside, figure, etc. will allow content creators to create documents more semantically. Previous development Authors generally use divs when implementing these functions.
Separation of content and display
The b and i tags are still retained, but their meanings are different from before. The meaning of these tags is only to identify a piece of text, not to Set bold or italic style. The tags u, font, center, and strike have been completely removed.
Added some new form input objects
Including date, URL, Email address, and other objects have added support for non-Latin characters. HTML5 also introduces microdata, a method of annotating content with machine-readable tags, making processing the Semantic Web easier. Overall, these structure-related improvements allow content creators to create cleaner, more manageable web pages that are more friendly to search engines, screen-reading software, and more.
New, more reasonable tags
Multimedia objects will no longer be all bound in object or embed Tag, but videos will have video tags, and audio will have audio tags.
Local Storage
This feature will embed a local SQL database to speed up interactive search, caching and indexing functions. At the same time, those offline Web programs will also benefit greatly from this. Rich animations that don’t require plugins.
Canvas object
will bring the browser the ability to draw vector graphics directly on it, which means that users can break away from Flash and Silverlight and display graphics or animations directly in the browser.
New API extensions
New API extensions are provided for the HTMLDocument and HTMLElement interfaces.
HTML5 replaces Flash and Silverlight
Syntax
1 Document Media Type
Most of the HTML syntax defined by HTML5 is compatible with HTML4 and XHTML1 , but some are incompatible. Most HTML documents are saved as text/html media type.
HTML5 defines detailed parsing rules (including error handling) for HTML syntax, and users must abide by these rules to save it as text/html media type. The following is an example that conforms to the HTML syntax specification:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>Example document</title> </head> <body> <p>Example paragraph</p> </body> </html>
HTML5 also defines a text/html-sandboxed media type for HTML syntax so that untrusted content can be hosted.
Other syntax that can be used in HTML5 is XML, which is compatible with XHTML1. If you use XML syntax, you need to save the document as an XML media type, and set the namespace to http://www.w3.org/1999/xhtml according to the XML specification.
The following example document complies with the XML syntax specification in HTML5. It should be noted that the XML document must be saved as an XML media type, such as application/xhtml+xml or application/xml.
<?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Example document</title> </head> <body> <p>Example paragraph</p> </body> </html>
2 Character Encoding
HTML5的HTML语法里,有三种形式可以声明字符串的encoding类型:
在传输级别(transport level)上,在HTTP实例的header里设置Content-Type。
在文件的开头设置一个Unicode的Byte Order Mark(BOM),该字符为文件的encoding方式提供了一个签名。
在文档的前1024个byte之前的内容里,使用带有charset属性的meta元素来声明encoding方式。例如:0d94b2dad07259293dd606022eaa23d8表明该文档是UTF-8格式的。它是替换原有的8d29369bdb665a142cf8029391b2aae6语法声明,尽管原有的语法依然可用,但在HTML5里不推荐使用。
对于HTML5里的XML语法,依然和以前的XML语法声明式一样的。
3 DOCTYPE
HTML5的HTML语法要求文档必须声明DOCTYPE以确保浏览器可以在标准模式下展示页面。这个DOCTYPE没有其它的目的,并且在XML里是可选项,因为XML媒体格式的文档一直就是在标准模式下处理的。
DOCTYPE的声明方式是8b05045a5be5764f313ed5b9168a17e6,不区分大小写。HTML的早期版本声明的DOCTYPE需要很长是因为HTML语言是建立在SGML的基础上,所以需要关联引用一个相对应的DTD。HTML5和之前的版本不一样了,仅仅需要声明DOCTYPE就可以告诉文档启用的是HTML5语法标准了,浏览器会为8b05045a5be5764f313ed5b9168a17e6做剩余的工作的。
4 MathML和SVG
HTML5的HTML语法允许在文档里使用MathML(数学标记语言)和SVG(可伸缩矢量图)元素。例如,一个非常简单的HTML页面包含一个svg元素画出的圆:
<!doctype html> <title>SVG in text/html</title> <p> A green circle: <svg> <circle r="50" cx="50" cy="50" fill="green"/> </svg> </p>
更多复杂的组合标记也是支持的,比如使用svg的foreignObject元素你可以嵌套MathML, HTML,或者自身嵌套。
5 其它
HTML5已经原生支持IRI了,尽管这些IRI只能在UTF-8和UTF-16的文档里使用。
lang属性如果设置的不合法,将会更新为空字符串,以告诉浏览器是一个未知的语言,作用和XML里的xml:lang一样。
以上就是HTML5学习笔记简明版(1):HTML5介绍与语法 的内容,更多相关内容请关注PHP中文网(www.php.cn)!