In this chapter we will briefly go through HTML5 attributes rules only.

Using lowercase attributes names

HTML5 allows mixing uppercase and lowercase letters in attribute names as well. Once again that is not suggested behavior.

Looking bad:

<p CLASS="nav">

Looking good:

<p class="nav">

Quoting of attribute values

HTML5 allows attribute values without quotes. It is recommended to quote attribute values for these reasons:

  • You have to use quotes anyway if the value contains spaces
  • Mixing styles is never good
  • Quoted values are easier to read
  • Unquoted values won't be read by an XML document

Bad example:

<p class=highlight>

Good example:

<p class="highlight">

Required Attributes

Remember to always use the alt attribute with images. It is important when the image cannot be viewed and you will score big bonuses with the search engines.

<img src="myimage.jpg" alt="My Image" style="width:180px; height:180px;" />

Try to always or most of the time to specify the image size because it has a heavy influence to the browser behavior and loading time. If the size is defined, a browser will be able to load the image before the page is uploaded, thus prevent unwanted behaviors such as flickering.

Spaces and equal signs

Usage of spaces around equal signs is allowed but omitting them is better for readability.

<link rel = "stylesheet" href = "styles.css">

Or:

<link rel="stylesheet" href="styles.css">

 

›› go to examples ››