MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Introduction to HTML5

HTML5 是目前最新的HTML標準。它提供一些新特性,不只是支援多媒體,還讓網頁應用程式可以更容易、更有效地與使用者、伺服器互動。

目前,仍有一些瀏覽器未完全支援HTML5所有特性。但是使用Gecko解析引擎的Firefox已經對HTML5十分支持,現時還繼續開發去支援更多特性。Gecko已經在1.8.1版本開始支持一些HTML5 了。你可以在main HTML5 page找到Gecko解析引擎最近支援的HTML5特性列表。若要更仔細知道多種瀏覽器支援的情況,可瀏覽CanIUse

建立HTML5文件並宣告HTML5 doctype

要建立HTML5文件很簡單,只需要在文件開首宣告:

<!DOCTYPE html>

對於未支援HTML5標準的瀏覽器,瀏覽器會繼續解析,但要注意一些HTML5的新特性則會忽略、不會支援。

然而這個宣告方法比以前HTML版本更簡單、更短,更容易記憶,亦減少文件容量。

利用<meta charset>來宣告字符集

你需要首先指示瀏覽器要使用哪一種字符集。在以前版本,這需要複雜的<meta>完素;來到HTML5,這變得非常簡單:

<meta charset="UTF-8">

將它放置在<head></head>之間。若果你使用的字符集與瀏覽器預先設定的不一樣,瀏覽器會重新解析文件。另外,若你目前並非UTF-8字符集,建議你在網頁中自行設定。

為了加強安全,HTML5文件限制字符集需要兼容ASCII和最少8位元。

Using the new HTML5 parser

The parsing rule of HTML5, which analyzes the meaning of mark-up, has 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 Web sites 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 write 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 Web site — the Web browsers' developers have done everything for you!

文件標籤與貢獻者

標籤: 
 此頁面的貢獻者: jackblackevo, kwanjaiOP
 最近更新: jackblackevo,