0% found this document useful (0 votes)
13 views4 pages

Cls 2

Uploaded by

Wisam Kayani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Cls 2

Uploaded by

Wisam Kayani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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 looks cleaner
 Lowercase is easier to write

Good:
<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>

Bad:
<a HREF="https://www.w3schools.com/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">

You might also like