All rules and guidelines in this document apply to HTML files.
The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
Icon Legend:
· Space, ⇥ Tab, ↵ Enter/Return
- Files
- Document
- Doctype
- Language
- Character Encoding
- Viewport
- Head And Body
- Comments
- Formatting
- Elements and Attributes
- Best Practices
This section describes the format and naming convention of HTML files.
- Character encoding MUST be set to UTF-8 without BOM
- Sublime.app →
File›Save with Encoding›UTF-8
- Sublime.app →
- Line endings MUST be set to Unix (LF)
- Sublime.app →
View›Line Endings›Unix
- Sublime.app →
- Letters MUST be all lowercase
- e.g.
sidebar.html,index.php
- e.g.
- Words MUST be separated with a hyphen
- e.g.
social-media.html,contact-widget.php
- e.g.
This section showcases the main elements required in a full HTML file.
- Doctype MUST be specified and SHOULD be HTML5
- e.g.
<!DOCTYPE html>
- e.g.
- Language MUST be defined in the
htmlelement- e.g.
<html lang="en">
- e.g.
- Character encoding MUST be defined as early as possible
- e.g.
<meta charset="utf-8">
- e.g.
- Viewport MUST be included
- e.g.
<meta name="viewport" content="width=device-width, user-scalable=no">
- e.g.
- Head and body elements MUST be included
- e.g.
<head></head><body></body>
- e.g.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome</h1>
<p>This is a skeleton document.</p>
</body>
</html>▲ Document
This section describes how comments should be formatted and used.
- Single-line comments MUST be on one line and the comment surrounded by spaces
- e.g.
<!-- This is a comment -->
- e.g.
- Multi-line comments MUST start and end on their own line
- i.e.
<!--↵Line number one↵Line number two↵`-->
- i.e.
- Closing tag comments SHOULD be prefixed with a
#or.followed by the name- e.g.
</div><!-- #main-wrapper -->
- e.g.
- Sensitive information MUST NOT be placed in a comment
- e.g.
<!-- Sends email to [email protected] -->
- e.g.
Single-line comments MUST be on one line and the comment surrounded by spaces.
<!--
This is a comment
-->↳ Incorrect because the one-line comment is not on one line.
<!--This is a comment-->↳ Incorrect because the comment is not surrounded by spaces.
<!-- This is a comment -->▲ Comments
Multi-line comments MUST start and end on their own line.
<!-- This is a comment
that spans multiple lines
-->↳ Incorrect because comment doesn't start and end on its own line.
<!--
This is a comment
that spans multiple lines
-->▲ Comments
Closing tag comments SHOULD be prefixed with either a # or . followed by the name.
<div id="main-wrapper">
...
</div><!-- main-wrapper -->↳ Incorrect because # prefix is missing.
<div id="main-wrapper">
...
</div><!-- .main-wrapper -->↳ Incorrect because main-wrapper is prefixed with . instead of #.
<div id="main-wrapper">
...
</div><!-- #main-wrapper -->▲ Comments
Sensitive information MUST NOT be placed in a comment.
<!-- Generated by some_php_function() -->↳ Incorrect because comments reveals server-side processes.
▲ Comments
This section outline various, general formatting rules related to whitespace and text.
- Line indentation MUST be accomplished using tabs
- i.e.
<ul>↵⇥<li>
- i.e.
- Direct child elements within
html,body,scriptorstyleelement MUST NOT be indented- i.e.
<head>↵⇥...</head>,<body><h1></h1></body>
- i.e.
- Block, list and table elements MUST start on a new line and their children MUST be indented
- i.e.
<div>↵⇥<h1>,<table>↵⇥<th>
- i.e.
- Trailing whitespace MUST NOT be present
- i.e. no
<p></p>··↵
- i.e. no
- Elements and attributes MUST be all lowercase
- e.g.
<a href="" title="">,<link rel="stylesheet" href="">
- e.g.
- Word separator MUST be a hyphen for user-defined attributes
- e.g.
<div data-user-name="">
- e.g.
Line indentation MUST be accomplished using tabs.
Direct child elements within html, body, script or style element MUST NOT be indented.
Block, list and table elements MUST start on a new line and their children MUST be indented.
Trailing whitespace MUST NOT be present.
Elements and attributes MUST be all lowercase.
Word separator MUST be a hyphen for user-defined attributes.
This section addresses how to utilize elements and attributes.
- Self-closing elements MUST NOT be closed
- e.g.
<br>,<link rel="stylesheet" href="">
- e.g.
- Optional open/close tags MUST be included
- e.g.
<ul><li></li></ul>
- e.g.
- Attribute order MUST be alphabetical and lead with required attributes
- e.g.
<input class="" id="" placeholder="" type="text" value="">
- e.g.
- Attribute values MUST be wrapped in double quotation marks
- e.g.
<a href="" title="">Link</a>
- e.g.
- Attribute booleans SHOULD NOT include a value
- e.g.
<input autofocus type="text">
- e.g.
- Type and language attribute MUST be omitted on
scripttags- e.g.
<script src=""></script>
- e.g.
- Type attribute MUST be omitted on
linkandstyletags- e.g.
<style src=""></script>
- e.g.
- Protocol SHOULD be omitted
- e.g.
<link href="//style.css" rel="stylesheet">
- e.g.
Self-closing elements MUST NOT be closed.
Optional open/close tags MUST be included.
Attribute order MUST be alphabetical and lead with required attributes.
Attribute values MUST be wrapped in double quotation marks .
Attribute booleans SHOULD NOT include a value.
Type and language attribute MUST be omitted on script tags.
Type attribute MUST be omitted on link and style tags.
Protocol SHOULD be omitted.
- Structures, styles and scripts SHOULD be separated from each other
- e.g.
<a class="button" data-track="pageview">Read More</a>
- e.g.
- Valid HTML SHOULD be written
- i.e. yes
<ul><li></li></ul>, no<ul><p></p></ul>
- i.e. yes
- Semantic HTML SHOULD be written
- i.e. yes
<a href="">View Options</a>, no<div class="click">View Options</div>
- i.e. yes
- Form fields SHOULD have a corresponding
label- e.g.
<label for=""></label><input id="" type="text">
- e.g.
- Entity references SHOULD NOT be used
- e.g. yes
—, no—
- e.g. yes
<strong>Get out!</strong>, <b>That compromised his system.</b>
Structures, styles and scripts SHOULD be separated from each other.
Valid HTML SHOULD be written.
Semantic HTML SHOULD be written.
Form fields SHOULD have a corresponding label.
Entity references SHOULD NOT be used.
Inspired in part by style guides from: CKAN, Google, jQuery, and WordPress.