5

For some html attributes, I can use quotes around the values, or not:

For example, I can do

<table colspan='1'></table>

Or

<table colspan=1></table>

Is there any difference between these two ways? Which is the more conventional way of doing things?

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
George Newton
  • 3,153
  • 7
  • 34
  • 49
  • To play nice with your fellow programmers and reduce errors, always use some form of quotes to delineate the values you are setting for your attributes. – Anil Jan 03 '14 at 01:43
  • 4
    And although this is a good question, it may be considered to be off-topic because it can lead to a subjective discussion, which is not something that SO is focused on. Cheers. – Anil Jan 03 '14 at 01:44
  • 3
    Related: [Do you quote HTML5 attributes?](http://stackoverflow.com/q/6495310) – Pekka Jan 03 '14 at 01:44
  • 3
    Related: [HTML properties without quotation marks?](http://stackoverflow.com/questions/9837063/html-properties-without-quotation-marks) – showdev Jan 03 '14 at 01:45
  • Thank you, the above links are very informative. – George Newton Jan 03 '14 at 02:07

1 Answers1

4

Wrap your values in quotes (single or double, just don't mix them):

  1. It's necessary for many values ( class="container modal warning" )
  2. It prevents confusing values with later attributes ( class="foo"id="bar" )
  3. People will like you, and treat you kindly.

During Tokenization, all three are considered (single, double, and none).

Sampson
  • 265,109
  • 74
  • 539
  • 565