Skip to content

Instantly share code, notes, and snippets.

@ourai
Last active December 15, 2015 22:39
Show Gist options
  • Save ourai/5334432 to your computer and use it in GitHub Desktop.
Save ourai/5334432 to your computer and use it in GitHub Desktop.
简单的 HTML 编码规范

HTML 规范

需要注意的几个点

  1. doctype 用html,这样大部分浏览器是激活的标准模式
  2. 标签都用小写
  3. html标签上要通过lang指定页面语言(中文、英文等)
  4. head标签中用meta指定页面的编码charset
  5. 把外联 CSS 在head标签中引入
  6. 把外联 JavaScript 在body标签最底部引入
  7. 自定义 HTML 属性用data-*的形式
  8. 在浏览器不能使用 JavaScript 时通过noscript标签进行提示
  9. 事件通过 JavaScript 来进行绑定并处理,不要写在 HTML 标签属性上

代码示例

<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <title>Spec of HTML</title>
        <link rel="stylesheet" href="./sample.css">
    </head>
    <body>
        <noscript>You had forbidden script. Please enable it.</noscript>
        <a id="t_a" data-self-attr="hello">Self-defined attribute</a>
        <script src="./sample.js"></script>
        <script>
            <!--
            document.getElementById( "t_a" ).addEventListener( "click", function() {
                // your code
            }, false);
            //-->
        </script>
    </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment