Do you quote HTML5 attributes?

Attribute quotes are optional in HTML5.

What are the pros and cons of quoting them?

id=example <!--quotes optional--> href=http://example.com <!--quotes optional--> class="example example-1" <!--quotes required due to space--> href="http://example.com/p=47" <!--quotes required due to '=' sign--> 

Update: Added benefits based on answers:

Benefits of quoting all attributes:

  • all editors can handle it right
  • more consistent
  • improved portability (easier to change doctype)
  • easier to maintain (especially if attributes can become empty)
  • easier to โ€œfind and replaceโ€ changes
  • clean doc (if you think quotes improve readability)

Advantages of excluding additional quotes:

  • file size slightly reduced
  • clean doc (if you prefer minimal text)
+59
performance html standards html5
Jun 27 '11 at 15:35
source share
5 answers

I am a supporter of always using quotation marks.

  • It looks cleaner and more consistent.

  • All editors can handle this correctly.

  • It is easier to maintain - you can edit the values โ€‹โ€‹without breaking them because there are no quotes.

A few bytes that you save in the size of the document, dropping the quotation marks where they are not needed, is not worth mentioning (if, perhaps, you are not the main page of Google).

+61
Jun 27 '11 at 15:37
source share

I will quote all attributes and will continue to do so. First of all, because it visually distinguishes where the attribute value starts and stops.

In addition, it makes sense for mobility and compatibility. Although quotation marks are optional in HTML [5], they are not optional in XHTML. You have a lot of tedious work if you need to convert your documents to XHTML (say, to display SVG in Webkit browsers). We really do not need to parse the XHTML v discussion. HTML, but it seems too little trouble not to bring your attributes.

Saving a few bytes in the body of the document is slightly negligible when you load kilobytes and kilobytes of images and JavaScript libraries.

+13
Jun 27 '11 at 15:43
source share

I think one of the advantages of quoting all attributes is consistency.

If you quote some (with spaces or specific characters), I would be better off quoting them all.

+7
Jun 27 '11 at 15:37
source share

I would say that since quotes are needed in some cases, you should use them sequentially. This makes your code cleaner and easier to read. Switching between simply creates unnecessary confusion.

+7
Jun 27 '11 at 15:38
source share

HTML5 was designed with backward compatibility in mind, so the citation attributes are fine. Many people argue that since XHTML requires quotes, it cannot hurt to always include them. Personally, I prefer to quote. Necessary? No.

Here are some guidelines that I think are reasonable. http://www.impressivewebs.com/html5-syntax-style/

+3
Jun 27 '11 at 15:42
source share



All Articles