Is there any difference between the following code blocks?
<iframe src="http://example.com" width=100%></iframe>
<iframe src=http://example.com width="100%"></iframe>
I've tried both and both seem to work, but I'm asking just in case there's something I need to be careful with?
The HTML standard does not require quotes around attribute values.
Attributes are always specified in the start tag (or opening tag) and usually consists of name/value pairs like name="value" . Attribute values should always be enclosed in quotation marks.
The official rules In the HTML 4.0 specification, section Attributes , the rule is formulated as follows: By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39).
The escape code " can also be used instead of " . Show activity on this post. Using " is the way to do it.
There is no practical difference except
Otherwise, the quotation marks are really needed only if the attribute value contains a space, a line break, an Ascii quotation mark ("), an Ascii apostrophe ('), a grave accent (`), an equals sign (=), a less than sign (<), or a greater than sign (>). So style = width:20em
would work (though it might be seen as somewhat obscure), whereas style = width: 20em
would not – due to the space, you would need to write style = "width: 20em"
.
Many people always write quotation marks around all attribute values, for simplicity. Others think that quotation marks make the code a bit messy, so they omit them when possible.
Quite independently of this, src="www.example.com"
means a relative URL reference, not what people expect to mean. You probably meant src="http://www.example.com"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With