首页 > 代码库 > basic html5

basic html5

  html4 doctype
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 HTML5 doctype:
 <!DOCTYPE html>

 In this example page, the root element looks like this:

  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

  The first thing to discuss is the xmlns attribute. This is a vestige of XHTML 1.0.
  It says that elements in this page are in the XHTML namespace, http://www.w3.org/1999/xhtml.
  But elements in HTML5 are always in this namespace, so you no longer need to declare it explicitly.
  Your HTML5 page will work exactly the same in all browsers, whether this attribute is present or not.

  Dropping the xmlns attribute leaves us with this root element:

  <html lang="en" xml:lang="en">

  Why two attributes for the same thing? Again, this is a vestige of XHTML. Only the lang attribute has any effect in HTML5.
  You can keep the xml:lang attribute if you like, but if you do, you need to ensure that it contains the same value as the lang attribute.

  Are you ready to drop it? It’s OK, just let it go. Going, going… gone! That leaves us with this root element:

  <html lang="en">

  Example page:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>My Weblog</title>
  <link rel="stylesheet" type="text/css" href="http://www.mamicode.com/style-original.css" />
  <link rel="alternate" type="application/atom+xml"
                        title="My Weblog feed"
                        href="http://www.mamicode.com/feed/" />
  <link rel="search" type="application/opensearchdescription+xml"
                        title="My Weblog search"
                        href="http://www.mamicode.com/opensearch.xml"  />
  <link rel="shortcut icon" href="http://www.mamicode.com/favicon.ico" />
</head>

对于
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;" charset="ISO-8859-1">
可以简化成
<meta charset="utf-8" />
对于
<link rel="stylesheet" href="http://www.mamicode.com/style-original.css" type="text/css" />
可以简化成
<link rel="stylesheet" href="http://www.mamicode.com/style-original.css" />

basic html5