Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do HTML attributes need quotation marks? [duplicate]

Tags:

html

web

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?

like image 845
Pete K. Avatar asked Mar 10 '23 10:03

Pete K.


1 Answers

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

like image 61
repzero Avatar answered Mar 20 '23 08:03

repzero