Introduction to HTML5 - Developer guides 编辑

HTML5 is the fifth revision and newest version of the HTML standard. It offers new features that provide not only rich media support but also enhance support for creating web applications that can interact with users, their local data, and servers more easily and effectively than was previously possible.

Some HTML5 features remain unsupported by some browsers. However, Gecko, and by extension, Firefox, has very good support for HTML5, and work continues toward supporting more of its features. Gecko began supporting some HTML5 features in version 1.8.1. You can find a list of all of the HTML5 features that Gecko currently supports on the main HTML5 page. For detailed information about multiple browsers' support of HTML5 features, refer to the CanIUse website.

Declaring that the document contains HTML5 mark-up with the HTML5 doctype

The doctype for HTML5 is very simple. To indicate that your HTML content uses HTML5, use:

<!DOCTYPE html>

Doing so will cause even browsers that don't presently support HTML5 to enter into standards mode, which means that they'll interpret the long-established parts of HTML in an HTML5-compliant way while ignoring the new features of HTML5 they don't support.

This is much simpler than the former doctypes, and shorter, making it easier to remember and reducing the amount of bytes that must be downloaded.

Declaring the character set with the <meta charset>

The first thing done on a page is usually indicating the character set that is used. In previous versions of HTML, it was done using a very complex <meta> element. Now, it is very simple:

<meta charset="UTF-8">

Place this right after your <head>, as some browsers restart the parsing of an HTML document if the declared character set is different from what they had anticipated. Also, if you are not currently using UTF-8, it's recommended that you switch to it in your web pages, as it simplifies character handling in documents using different scripts.

Note that HTML5 restricts character sets to those compatible with ASCII and using at least 8 bits. This was done to tighten security and prevent some types of attacks.

Using the new HTML5 parser

The parsing rules of HTML5, which analyze the meaning of mark-up, have been more precisely defined in HTML5. Until the introduction of HTML5, only the meaning of valid mark-up was defined, meaning that as soon as one small error was made in the mark-up (most websites have at least one), the behavior was undefined. Essentially, it meant that all browsers behaved differently, which is no longer the case. Now, faced with errors in the mark-up, all compliant browsers must behave exactly in the same way.

This requirement helps web developers quite a bit. While it is true that all modern browsers now use these HTML5 parsing rules, non-HTML5-compliant browsers are still used by some. Keep in mind that it's still highly recommended that one writes valid mark-up, as such code is easier to read and maintain, and it greatly decreases the prominence of incompatibilities that exists in various older browsers.

Don't worry — you don't have to change anything on your website. The web browsers' developers have done everything for you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:42 次

字数:4392

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文