Double quotes or single quotes in HTML?

7

Personally I like to use double quotes about attributes / HTML values, but I have seen codes where the use of single quotes is what dominates the document and even! some with absence of quotes.

<input type="text" name="age" />
<input type='text' name='age' />
<input type=text name=age />

Apart from knowing the compatibility of its use there are with browsers, I would like to know which of those forms to use and why? Is there any functional implication that affects performance?

Example:

In many programming languages; the difference between single and double quotation marks to declare the text strings, is the interpolation, but it is necessary to discuss that about HTML because we know it does not fall into that category. But is there any behavior that alters the way of presenting the data?

    
asked by Chofoteddy 17.12.2018 в 05:25
source

1 answer

11

Summary

Double quotes are used because at the beginning of the tagging language ( SGML ), authors could do use of special characters (which were sometimes difficult to enter, if not impossible through the keyboard) just by typing your reference, p. eg:

  • "&amp;lt;" represents the% sign < .
  • "&amp;gt;" represents the% sign > .
  • "&amp;quot;" represents the% sign " .
  • "&amp;#229;" (in decimal) represents the letter a with a small circle on it.
  • Among others ...

In a nutshell, like some programming languages, they enjoyed rich functionality compared to single quotes.

Source: W3C - HTML4 .

Explanation

The official document of the W3C (on HTML5 syntax) mark that it is perfectly correct the use of the attribute-value pair with single quotes, double quotes or even with absence of quotation marks; Clear! each with certain rules.

Value of the attribute without quotes

  

The name of the attribute, followed by one or more space characters, followed by a single character U + 300D EQUAL SIGN, followed by one or more space characters, followed by the value of the attribute, which , in addition to the requirements provided ..., you must dispense with any literal space character , of any U + 0022 QUOTATION MARK (single quotes), U + 0027 APOSTROPHE (apostrophe), U + 003D EQUALS SIGN (equal sign), U + 003C LESS-THAN SIGN (less than), U + 003E GREATER-THAN SIGN (greater than) or U + 0060 GRAVE ACCENT (grave accent), and should not be an empty string.

Value of the attribute with single quotes

  

The name of the attribute, followed by one or more space characters, followed by a single character U + 300D EQUAL SIGN (equal sign), followed by one or more space characters, followed by U + 0027 APOSTROPHE (apostrophe ), followed by the value of the attribute, which, in addition to the requirements provided ..., must dispense with any character of U + 0027 APOSTROPHE (literal apostrophe) and finally followed by another U + 0027 APOSTROPHE (apostrophe).

Value of the attribute with double quotes

  

The name of the attribute, followed by one or more space characters, followed by a single character U + 300D EQUAL SIGN (equals sign), followed by one or more space characters, followed by U + 0022 QUOTATION MARK ( English quote), followed by the value of the attribute, which, in addition to the requirements provided ..., must dispense with any character of U + 0022 QUOTATION MARK (English quote) and finally followed by another U + 0022 QUOTATION MARK (English quote ).

Derived from all this (and probably the custom) the W3C uses in its examples double quotes or without quotes, it is for convenience and sometimes good practices to promote the same thing that the official documentation urges you to do based on your examples, do the opposite It's like trying to cut down a tree, going against the grain of the wood.

    
answered by 17.12.2018 / 05:25
source