1. Computing & Technology

Discuss in my forum

Are quotes required around HTML 5 attributes?

By , About.com Guide

Question: Are quotes required around HTML 5 attributes?

In XHTML, all attribute values must be quoted using double quote marks.

Answer:

When writing HTML 5 attributes, you do not need to use quotation marks to define the value. When you don't use quotation marks you cannot use the following characters in your attribute values:

  • double and single quote marks (" and ')
  • spaces ( )
  • equal sign (=)
  • greater-than sign (>)

In order to use those characters with unquoted attribute values you must either escape them using HTML codes or you must quote your attribute values.

Examples of Correct and Incorrect HTML 5 Attributes

Incorrect HTML 5 attributes:

<p class=blah blah>
<p class=blah=blah>
<p class=blah>blah>
<p class=blah'blah>
<p class=blah"blah>

Correct HTML 5 attributes:

<p class=blahblah>
<p class="blah blah">
<p class=blah&#61;blah>
<p class=blah&gt;blah>
<p class="blah'blah">
<p class='blah"blah'>

©2012 About.com. All rights reserved.

A part of The New York Times Company.