The best HTML (5) Code Specification Tutorial In 2024, In this tutorial you can learn HTML Code Conventions,Use the correct type of document,Lowercase element names,Turn off all HTML elements,Close empty HTML elements,Lowercase attribute name,Property Value,Image properties,Spaces and equal signs,Avoid long line of code,Blank lines and indentation,Omit the <html> and <body>?,Omit the <head>?,Metadata,HTML comments,Stylesheet,Loading JavaScript in HTML,Use JavaScript to access HTML elements,Lowercase filenames,File extension,The difference between .htm and .html,Technically difference,
Many Web developers HTML code specification poorly understood.
In 2000-2010, many Web developers to convert from HTML to XHTML.
Developers use XHTML gradually develop a good HTML writing specifications.
And for in HTML5, we should form a relatively good code norms, several recommendations are provided below specification.
The document type declaration in the first row of the HTML document:
If you want to use other labels, like lower case, you can use the following code:
HTML5 element name can use uppercase and lowercase letters.
Recommended use lowercase letters:
In HTML5, you do not want to close all of the elements (for example, <p> element), but we recommend that each element must add a closing tag.
Not recommended:
recommend:
In HTML5, empty HTML element does not have to shut down:
We can write:
You can also write:
XML, XHTML and slash (/) is a must.
If you expect to use your software XML page, this style is very good.
HTML5 allows the use of the property name uppercase and lowercase letters.
We recommend using lowercase attribute name:
Not recommended:
recommend:
HTML5 attribute values can not quote.
We recommend using the attribute value quotes:
The following examples attribute value contains spaces, do not use quotation marks, it can not work:
The following uses double quotation marks, it is correct:
Image alt attributes often used. When the image can not be displayed, it can replace image display.
Defined image size, can be reserved at the time of loading specified space, reduce flicker.
You can use spaces before and after the equal sign.
However, we recommend using less space:
Using an HTML editor, left and right scrolling code is inconvenient.
Each line of code as much as possible less than 80 characters.
Do not add a blank line for no reason.
For each logic function block add a blank line, which makes it easier to read.
Indent two spaces, not recommended TAB.
Do not use unnecessary blank lines are indented between short code.
In the HTML5 standard, <html> and <body> tag can be omitted.
The following documents are correct HTML5:
Not recommended omitted <html> and <body> tag.
<Html> element is the root element of the document, the language used to describe the page:
Language statement is to facilitate screen readers and search engines.
Omit the <html> or <body> in the DOM and XML software crashes.
Omit the <body> error occurs in older browsers (IE9).
In the HTML5 standard, <head> tag can be omitted.
By default, the browser will content <body> before added to a default <head> element.
Now omit the head tags are not recommended. |
HTML5 in the <title> element is required, the name of the title describes the theme of the page:
Title and language that allows the search engine will soon understand the theme of your page:
Comments can be written in the <- and -!> In:
Longer comments in the <! - And -> wrote in branches:
The comments of the first character indent two spaces, easier to read.
Stylesheet terse syntax (type attribute is not required):
Rules can be written as a short line:
Long multi-line rules can be written:
After the comma and semicolon add spaces is a common rule. |
Use simple syntax to load external script file (type attribute is not required):
A bad HTML format may cause the execution of JavaScript errors.
The following two JavaScript statements to output different results:
HTML, JavaScript Try to use the same naming convention.
Access JavaScript code specifications .
Most Web servers (Apache, Unix) are case sensitive: london.jpg London.jpg can not access.
Other Web servers (Microsoft, IIS) is not case sensitive: london.jpg can be accessed via London.jpg or london.jpg.
You must maintain a unified style, we recommend consistent use lowercase file names.
HTML file suffix can be (or r .htm).
CSS file extension is .css.
JavaScript file suffix .js.
The file extension .htm and on the nature there is no difference. Browser and the Web server will treat them as HTML files to deal with.
The difference is that:
.htm application in early DOS systems, or systems are now only three characters.
Suffix is not particularly limited to Unix systems, usually with .
If a URL does not specify a file name (such as http://www.w3write.com/css/), the server will return to the default file name. The default file name is usually index, index.htm, default, and default.htm.
If the server is configured with only "index" as the default file, you must name the file "index", rather than "index.htm".
Generally, however, the server can set up multiple default file, you can set the default file it as needed.
Anyway, HTML full suffix is "".