HTML Style Guide
A consistent, clean, and tidy HTML code makes it easier for others to read and understand your code.
Here are some guidelines and tips for creating good HTML code.
Always Declare Document Type
Always declare the document type as the first line in your document.
The correct document type for HTML is:
<!DOCTYPE html>
Use Lowercase Element Names
HTML allows mixing uppercase and lowercase letters in element names.
However, we recommend using lowercase element names, because:
- Mixing uppercase and lowercase names looks bad
- Developers normally use lowercase names
- Lowercase looks cleaner
- Lowercase is easier to write
Good:
<body> <p>This is a paragraph.</p> </body>
Bad:
<BODY> <P>This is a paragraph.</P> </BODY>
Close All HTML Elements
In HTML, you do not have to close all elements (for example the <p>
element).
However, we strongly recommend closing all HTML elements, like this:
Good:
<section> <p>This is a paragraph.</p> <p>This is a paragraph.</p> </section>
Bad:
<section> <p>This is a paragraph. <p>This is a paragraph. </section>
Use Lowercase Attribute Names
HTML allows mixing uppercase and lowercase letters in attribute names.
However, we recommend using lowercase attribute names, because:
- Mixing uppercase and lowercase names looks bad
- Developers normally use lowercase names
- Lowercase look cleaner
- Lowercase are easier to write
Good:
<a href="https://apostube.com/category/html/">Visit our HTML tutorial</a>
Bad:
<a HREF="https://apostube.com/category/html/">Visit our HTML tutorial</a>
Always Quote Attribute Values
HTML allows attribute values without quotes.
However, we recommend quoting attribute values, because:
- Developers normally quote attribute values
- Quoted values are easier to read
- You MUST use quotes if the value contains spaces
Good:
<table class="striped">
Bad:
<table class=striped>
Very bad:
This will not work, because the value contains spaces:
<table class=table striped>
Always Specify alt, width, and height for Images
Always specify the alt
attribute for images. This attribute is important if the image for some reason cannot be displayed.
Also, always define the width
and height
of images. This reduces flickering, because the browser can reserve space for the image before loading.
Good:
<img src="html5.gif" alt="HTML5" style="width:128px;height:128px">
Bad:
<img src="html5.gif">
Spaces and Equal Signs
HTML allows spaces around equal signs. But space-less is easier to read and groups entities better together.
Good:
<link rel="stylesheet" href="styles.css">
Bad:
<link rel = "stylesheet" href = "styles.css">
Avoid Long Code Lines
When using an HTML editor, it is NOT convenient to scroll right and left to read the HTML code.
Try to avoid too long code lines.
Blank Lines and Indentation
Do not add blank lines, spaces, or indentations without a reason.
For readability, add blank lines to separate large or logical code blocks.
For readability, add two spaces of indentation. Do not use the tab key.
Good:
<body> <h1>Famous Cities</h1> <h2>Tokyo</h2> <p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p> <h2>London</h2> <p>London is the capital city of England. It is the most populous city in the United Kingdom.</p> <h2>Paris</h2> <p>Paris is the capital of France. The Paris area is one of the largest population centers in Europe.</p> </body>
Bad:
<body> <h1>Famous Cities</h1> <h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p> <h2>London</h2><p>London is the capital city of England. It is the most populous city in the United Kingdom.</p> <h2>Paris</h2><p>Paris is the capital of France. The Paris area is one of the largest population centers in Europe.</p> </body>
Good Table Example:
<table> <tr> <th>Name</th> <th>Description</th> </tr> <tr> <td>A</td> <td>Description of A</td> </tr> <tr> <td>B</td> <td>Description of B</td> </tr> </table>
Good List Example:
<ul> <li>London</li> <li>Paris</li> <li>Tokyo</li> </ul>
Never Skip the <title> Element
The <title>
element is required in HTML.
The contents of a page title is very important for search engine optimization (SEO)! The page title is used by search engine algorithms to decide the order when listing pages in search results.
The <title>
element:
- defines a title in the browser toolbar
- provides a title for the page when it is added to favorites
- displays a title for the page in search-engine results
So, try to make the title as accurate and meaningful as possible:
<title>HTML Style Guide and Coding Conventions</title>
Omitting <html> and <body>?
An HTML page will validate without the <html>
and <body>
tags:
Example
<!DOCTYPE html> <head> <title>Page Title</title> </head> <h1>This is a heading</h1> <p>This is a paragraph.</p>
However, we strongly recommend to always add the <html>
and <body>
tags!
Omitting <body>
can produce errors in older browsers.
Omitting <html>
and <body>
can also crash DOM and XML software.
Omitting <head>?
The HTML <head> tag can also be omitted.
Browsers will add all elements before <body>
, to a default <head>
element.
Example
<!DOCTYPE html> <html> <title>Page Title</title> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
However, we recommend using the <head>
tag.
Close Empty HTML Elements?
In HTML, it is optional to close empty elements.
Allowed:
<meta charset="utf-8">
Also Allowed:
<meta charset="utf-8" />
If you expect XML/XHTML software to access your page, keep the closing slash (/), because it is required in XML and XHTML.
Add the lang Attribute
You should always include the lang
attribute inside the <html>
tag, to declare the language of the Web page. This is meant to assist search engines and browsers.
Example
<!DOCTYPE html> <html lang="en-us"> <head> <title>Page Title</title> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
Meta Data
To ensure proper interpretation and correct search engine indexing, both the language and the character encoding <meta charset="charset">
should be defined as early as possible in an HTML document:
<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="UTF-8"> <title>Page Title</title> </head>
Setting The Viewport
The viewport is the user’s visible area of a web page. It varies with the device – it will be smaller on a mobile phone than on a computer screen.
You should include the following <meta>
element in all your web pages:
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
This gives the browser instructions on how to control the page’s dimensions and scaling.
The width=device-width
part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).
The initial-scale=1.0
part sets the initial zoom level when the page is first loaded by the browser.
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.
-->
Long comments are easier to observe if they are indented with two spaces.
Using Style Sheets
Use simple syntax for linking to style sheets (the type
attribute is not necessary):
<link rel="stylesheet" href="styles.css">
Short CSS rules can be written compressed, like this:
p.intro {font-family:Verdana;font-size:16em;}
Long CSS rules should be written over multiple lines:
body {
background-color: lightgrey;
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;
}
- Place the opening bracket on the same line as the selector
- Use one space before the opening bracket
- Use two spaces of indentation
- Use semicolon after each property-value pair, including the last
- Only use quotes around values if the value contains spaces
- Place the closing bracket on a new line, without leading spaces
Loading JavaScript in HTML
Use simple syntax for loading external scripts (the type
attribute is not necessary):
<script src=”myscript.js”>
Accessing HTML Elements with JavaScript
Using “untidy” HTML code can result in JavaScript errors.
These two JavaScript statements will produce different results:
Example
getElementById("Demo").innerHTML = "Hello";
getElementById("demo").innerHTML = "Hello";
Use Lower Case File Names
Some web servers (Apache, Unix) are case sensitive about file names: “london.jpg” cannot be accessed as “London.jpg”.
Other web servers (Microsoft, IIS) are not case sensitive: “london.jpg” can be accessed as “London.jpg”.
If you use a mix of uppercase and lowercase, you have to be aware of this.
If you move from a case-insensitive to a case-sensitive server, even small errors will break your web!
To avoid these problems, always use lowercase file names!
File Extensions
HTML files should have a .html extension (.htm is allowed).
CSS files should have a .css extension.
JavaScript files should have a .js extension.
48 Responses
levofloxacin 500mg ca levaquin 250mg cost
order avodart 0.5mg without prescription ondansetron brand buy zofran generic
order aldactone 25mg online cheap aldactone 100mg us diflucan 200mg generic
ampicillin 250mg price buy trimethoprim pills erythromycin 250mg generic
fildena 50mg brand robaxin 500mg us methocarbamol cheap
order sildenafil 50mg for sale suhagra 50mg brand estrace generic
cheap lamictal order tretinoin cream buy tretinoin sale
tadalafil 10mg drug diclofenac 50mg ca diclofenac 50mg oral
isotretinoin 20mg cost amoxil 500mg brand order zithromax 250mg pill
indomethacin 50mg price amoxicillin 500mg canada trimox price
cialis 40mg usa erectal disfunction brand sildenafil
anastrozole 1 mg brand Low cost viagra sildenafil drug
order prednisone 10mg online online buy cialis sildenafil pills
cialis 5mg für männer cialis 20mg für frauen original sildenafil 200mg rezeptfrei sicher kaufen
accutane 20mg for sale buy zithromax 250mg stromectol order
order modafinil generic oral diamox 250 mg diamox 250mg sale
doxycycline brand buy clomid without prescription lasix 100mg uk
brand altace 10mg order generic clobetasol buy azelastine online cheap
buy generic catapres 0.1mg order minocin generic buy generic tiotropium bromide 9mcg
buy buspar 10mg order oxybutynin 5mg pills order ditropan 5mg pill
order generic terazosin 1mg order pioglitazone 30mg generic sulfasalazine 500mg sale
fosamax 70mg brand purchase fosamax pills cheap famotidine 20mg
buy generic benicar 20mg diamox 250mg cheap acetazolamide 250mg without prescription
prograf 5mg pill ropinirole 2mg without prescription order ursodiol 150mg online cheap
buy isosorbide 40mg without prescription micardis 80mg generic order micardis pills
buy zyban generic buy cetirizine 10mg buy seroquel 100mg without prescription
molnupiravir 200mg over the counter cefdinir 300 mg without prescription brand prevacid
purchase sertraline for sale order lexapro online buy viagra sale
imuran canada purchase viagra online cheap sildenafil citrate
tadalafil 5mg pills order cialis 40mg online order sildenafil 50mg without prescription
buy tadalafil 10mg for sale purchase amantadine for sale symmetrel online buy
revia 50mg without prescription albendazole brand order abilify 20mg for sale
dapsone 100mg us allegra canada buy perindopril online
buy modafinil 100mg without prescription recommended canadian online pharmacies price of ivermectin tablets
luvox 50mg over the counter order generic duloxetine order glucotrol without prescription
piracetam cheap buy viagra 100mg online order viagra online
zithromax 500mg without prescription purchase zithromax pills gabapentin medication
order tadalafil 20mg online cheap generic tadalafil cheap sildenafil online
buy generic lasix lasix pills order hydroxychloroquine 400mg pills
generic cialis 20mg betamethasone for sale buy anafranil 50mg
Hello bro!Click here…
дом престарелых
https://pansionat-rnd.ru/
“Дом престарелых” (больница для престарелых) – это медицинское учреждение, которое предоставляет круглосуточную медицинскую и социальную помощь для престарелых людей, которые не могут жить независимо. В доме престарелых может быть оказана медицинская помощь, реабилитация, питание, гигиеническая и психологическая помощь и другие услуги.
дом престарелых в Ростове-на-Дону
http://images.google.com.sg/url?q=https://pansionat-rnd.ru/ http://www.google.gg/url?q=https://pansionat-rnd.ru/ https://images.google.co.ao/url?q=https://pansionat-rnd.ru/ http://cse.google.ne/url?q=https://pansionat-rnd.ru/ https://maps.google.cg/url?q=https://pansionat-rnd.ru/
출장마사지
Fantastic pictures, the colour and depth of the pictures are breath-taking, they attract you in as though you are a component of the make-up.
https://cordiant-1.online
https://akita-kennel.ru
https://seo-top-site.ru
https://goodyear1.online
https://o-dom2.ru
https://prodvizhenie-sait.ru
https://mytop-site.ru
https://yokohama1.online
https://testcars.ru
https://bridgestone2.ru
https://pirelli1.online
https://seo-privat.ru
https://vash1host.ru
https://sekup.ru
https://kormoran1.online
https://toyo1.online
https://kupitshin.online
https://domodedovo2012.ru
https://hankook1.online
https://michelin1.online
https://nokian1.online
https://tireservice1.online
https://nokian1.online
отзывы blizzak dm-v2
зимняя резина ultra grip ice arctic suv
Davidbem
https://mytop-site.ru
сео продвижение сайта москва
продвижение контекстная реклама
https://o-dom2.ru
sailun atrezzo elite 215 55 17
шины континенталь
FloydCew
https://pirelli1.online
сео раскрутка
продвижение сайта предприятия
https://kormoran1.online
летние шины 215 65 17
шины зимние купить
FloydCew
https://kupitshin.online
seo продвижения
сео продвижение цена в месяц
ErnestEvage
https://xn—24-7-4vevhge6enkbeai0a1a5dye2c.xn--p1ai
https://xn—24-7-3vebnd9cxa7amcgy4al.xn--p1ai
https://xn—-24-7-3nfzigf2folbfai2a2a8d2e3c.xn--p1ai
https://xn—-24-7-2nfbpd5dza0bncg0a6al.xn--p1ai
https://xn—24-7-3vebi7a0c8ajhwdyl9mh.xn--p1ai/
https://xn--24-7–3vefjh5cxa7amcku4ap.xn--p1ai
https://xn—24-7-3vebahb3baz2czbsdzdf9b3a4x.xn--p1ai/
ErnestEvage
https://xn—-24-7-2nfbpd5dza0bncg0a6al.xn--p1ai
https://xn—24-7-3vebahb3baz2czbsdzdf9b3a4x.xn--p1ai/
https://xn--24-7–3vefjh5cxa7amcku4ap.xn--p1ai
https://xn—24-7-3vebi7a0c8ajhwdyl9mh.xn--p1ai/
https://xn—24-7-3vebnd9cxa7amcgy4al.xn--p1ai
https://xn—24-7-4vevhge6enkbeai0a1a5dye2c.xn--p1ai
https://xn—-24-7-3nfzigf2folbfai2a2a8d2e3c.xn--p1ai