HTML5 Style Guide and Coding Conventions
HTML Coding Conventions
Web developers are frequently indeterminate about the coding style and linguistic structure to use in HTML.
In the vicinity of 2000 and 2010, many web developers changed over from HTML to XHTML.
With XHTML, developers were compelled to compose legitimate and "all around framed" code.
HTML5 is more messy with regards to code approval.
Use Correct Document Type
<!DOCTYPE html>
If you want consistency with lower case tags, you can use:
<!doctype html>
Use Lower Case Element Names
HTML5 allows mixing uppercase and lowercase letters in element names.
Bad:
<SECTION>
<p>This is a paragraph.</p>
</SECTION>
<p>This is a paragraph.</p>
</SECTION>
Very Bad:
<Section>
<p>This is a paragraph.</p>
</SECTION>
<p>This is a paragraph.</p>
</SECTION>
Good:
<section>
<p>This is a paragraph.</p>
</section>
<p>This is a paragraph.</p>
</section>
Image Attributes
Continuously include the "alt" ascribe to pictures. This characteristic is imperative when the picture for reasons unknown can't be shown. Likewise, dependably characterize picture width and stature. It decreases gleaming on the grounds that the program can save space for the picture before stacking.
Bad:
<img src="html5.gif">
Good:
<img src="html5.gif" alt="HTML5" style="width:128px;height:128px">
Spaces and Equal Signs
HTML5 allows spaces around equal signs. But space-less is easier to read, and groups entities better together.
Bad:
<link rel = "stylesheet" href = "styles.css">
Good:
<link rel="stylesheet" href="styles.css">
Omitting <head>?
In the HTML5 standard, the <head> tag can likewise be excluded.
Of course, programs will include all components previously <body>, to a default <head> component.
You can decrease the many-sided quality of HTML, by precluding the <head> tag:
Example
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<html>
<title>Page Title</title>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Meta Data
<title>HTML5 Syntax and Coding Style</title>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>HTML5 Syntax and Coding Style</title>
</head>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>HTML5 Syntax and Coding Style</title>
</head>
HTML Comments
Short comments should be written on one line, like this:
<!-- This is a comment -->
Comments that spans more than one line, should be written like this:
<!--
This is a long comment example. This is a long comment example.
This is a long comment example. This is a long comment example.
-->
This is a long comment example. This is a long comment example.
This is a long comment example. This is a long comment example.
-->
Style Sheets
Use simple syntax for linking to style sheets (the type attribute is not necessary):
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="styles.css">
Short rules can be written compressed, on one line, like this:
p.intro {font-family: Verdana; font-size: 16em;}
p.intro {font-family: Verdana; font-size: 16em;}
Long rules should be written over multiple lines:
body {
background-color: lightgrey;
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;}
body {
background-color: lightgrey;
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;}
background-color: lightgrey;
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;}
0 comments:
Post a Comment