6

I am working on a web site, and am wondering if you need to put quotation marks around HTML attributes for example I've seen code like:
<img src=http://example.com/image.jpg width=350px height=200px />
instead of:
<img src="http://example.com/image.jpg" width="350px" height="200px" />.
Does anyone know the answer to this?

Pete K.
  • 112
  • 3
  • 11
  • 3
    It's best practice to have double-quotes for attributes; specially for those that contain multiple elements within (i.e. `style="width:300px; height: 200px;"`, etc.) – blurfus Apr 06 '17 at 01:54

1 Answers1

10

If the attribute contains a string that is not ascii or has whitespace then you need to wrap it in quotes

Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.

link here

repzero
  • 8,254
  • 2
  • 18
  • 40