What kind of quotes do you use when programming HTML ? I use '
Example :
HTML Code:<img src="img.png"> <img src='img.png'> <img src=img.png>
| SitePoint Sponsor |
"
'
[Both]
[No quotes]


What kind of quotes do you use when programming HTML ? I use '
Example :
HTML Code:<img src="img.png"> <img src='img.png'> <img src=img.png>


While both work 90% of the time, I've found that there are a few buggy browsers out there that get confused by single quotes, so I've standardized with double quotes across my sites.
Michael Moncur - The Quotations Page | My other sites | My Books
JavaScript Weblog | Webmaster Tips
Gadgets | Fitness Weblog | My Weblog
According to http://www.w3.org/TR/xhtml1/#h-4.4 all attributes must be quoted - which makes the double quote the correct method - nothing else.
John
No electrons were harmed during the creation, transmission
or reading of this posting. However, many were excited and
some may have enjoyed the experience.
I use doube quotes. Incidentally, do you need to encapsulate integers in quotes in HTML? I know that you don't in most programming languages, so what about HTML?![]()
(X)HTML does not discriminate about the type of assignment to an attribute. You quote them all. It is the action of assignment rather the apparent data type or content of the assignee that is the issue.Originally Posted by compuwhiz7
John
No electrons were harmed during the creation, transmission
or reading of this posting. However, many were excited and
some may have enjoyed the experience.
Since HTML is not a programming language and knows nothing about data types, yes you have to quote them.Originally Posted by compuwhiz7
As for the question, I use double quotes; always have.



I use double quotes too.
Also, just to be picky:
<img src="image.png" alt="This is an Image!!!" style="width: 200px; height: 200px" />
Better![]()
Except that XHTML 1.1 deprecates inline styles. See http://www.w3.org/TR/xhtml11/doctype.html#s_doctypeOriginally Posted by N9ne
And http://www.w3.org/TR/xhtml-modulariz...#s_imagemodule says: that an img tag should have alt* (Text), height (Length), longdesc (URI), src* (URI), width (Length) as attributes so IMHO it is incorrrect to specify length and height in a style declaration, and they should be declared directly.
John
No electrons were harmed during the creation, transmission
or reading of this posting. However, many were excited and
some may have enjoyed the experience.
yep, same for <object> as wellOriginally Posted by John Colby
![]()


That's XHTML, I program HTML and PHP. And because of that, I'm too lazy to do this :Originally Posted by John Colby
With me...PHP Code:<?php
echo"<img src=\"img.png\">";
?>
I find it easier than hitting the [SHIFT] key all the time as well as adding backslashes...PHP Code:<?php
echo"<img src='img.png'>";
?>
Thisn is nnow getting confusing. The http://www.w3.org/MarkUp/html-spec/html-spec_3.html says
Attributes
In a start-tag, white space and attributes are allowed between the element name and the closing delimiter. An attribute specification typically consists of an attribute name, an equal sign, and a value, though some attribute specifications may be just a name token. White space is allowed around the equal sign.
The value of the attribute may be either:
* A string literal, delimited by single quotes or double quotes and not containing any occurrences of the delimiting character. (7)
* A name token (a sequence of letters, digits, periods, or hyphens). Name tokens are not case sensitive. (8)
In this example, img is the element name, src is the attribute name, and `http://host/dir/file.gif' is the attribute value:
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 says (HTML4)
However no examples on either HTML or XHTML show single quotes.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). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa. Authors may also use numeric character references to represent double quotes ("and single quotes ('
. For double quotes authors can also use the character entity reference ".
The validators accept either.
John
No electrons were harmed during the creation, transmission
or reading of this posting. However, many were excited and
some may have enjoyed the experience.
Why not:Originally Posted by giropets
Unless you're throwing a variable in there, you can do what I did above just fine. There goes your argumentPHP Code:<?php
echo '<img src="img.png" />';
?>.



I use " for sure.
+ Carbonmade - Easiest way to display and manage your portfolio.
+ Burstoid - Design magazine.
+ twitter/spencerfry


Originally Posted by John Colby
I've talked to a Programming Expert in the past about this. He told me that browsers accept all three of them. He said it didn't matter which I use.
The only thing is that if you use it without any kind of quotes..it'll only pick up the first value.
Ex :
It'll only pick up 'Click'.HTML Code:<input type=Submit value=Click Me>
Just take a quick look at www.neopets.com, they're one of the biggest sites on the net. If you look at their HTML source code, you'll see that they don't use quotes and sometimes use single quotes.
At this very second, they have 66,098,612 accounts on their site with 116,622,550,000 page views.
Ex :
HTML Code:<img src="http://images.neopets.com/blank.gif" width=2 height=5>If they're one of the most popular sites on the net, then how come they still have single quotes and sometimes no quotes ?HTML Code:<font size=1 color=#666666>NEOPETS, characters, logos, names and all related indicia<br> are trademarks of <a href='/aboutus.phtml'><font size=1>Neopets, Inc.,</a><font size=1 color=#666666> © 1999-2003. All rights reserved.</font><br> <a href='/privacy.phtml'><font size=1>Privacy Policy</a> | <a href='/safetytips.phtml'><font size=1>Safety Tips</a> | <a href='/contact.phtml'><font size=1>Contact Us</a> | <a href='/aboutus.phtml'><font size=1>About Us</a> | <a href='/presskit_form.phtml'><font size=1>Press Kit</a>





Becuase they don't know better.Originally Posted by giropets
Seriuosly. It doesn't make it more correct/ok to break the standards because a large site do it.
Getting the quotes correct is a very simple task though.
-Helge


Generally it is optional whether single or double are used though to be on the safe-side it is generally preferable to use double.
However, let us consider:The above would be legal XHTML whereas if the author had chosen to use double quotes for Times New Roman they would have failed validation.Code:<div style="font-face: 'Times New Roman', Times, Georgia, Serif;">X</div>
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?





I generally use " in HTML. However, if I am outputting HTML through
ASP I prefer the single ' because it simply makes the
code a little easier to see and takes up less room in monospaced fonts.





This would also have passed validation:Originally Posted by xhtmlcoder
-HelgeCode:<div style="font-face: Times New Roman, Times, Georgia, Serif;">X</div>![]()
Originally Posted by Helge
Off Topic:
Yeah, you and xhtmlcoder would have passed XHTML validation, but you both would have failed at CSS validation. It's font-family!





Let's stay on topic shall we.![]()
![]()
-Helge


Ah yes, I didn't have my CSS Santa hat on since it was markup that was in question (I don't know how I managed to write face instead of family probably my dyslexia)..
Also I have to use a similar nesting method with my ICRA labels.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?


Originally Posted by Helge
I'm saying that because they're a big site. They are one of the biggest sites on the internet. Because of that, their visitors will have many different browsers -- some of which may not be compatable to that. Or so you say. Then if they get so many members, then why isn't all of their code with double quotes ?
I don't agree with the rest of you. The most browser efficient way to quote or define html is transversal. There is no ONE quote you use, because this would overlap. Heres an example of what I use.
And for server side scripts I would use:HTML Code:<img height=0 width=0 src="image.jpg">
I don't usually program in php, but that is how I do my quotes. For asp I would reverse it and just use:PHP Code:<?php echo '<img height=0 width=0 src="image.jpg">'; ?>
Response.Write "<img height=0 width=0 src='image.jpg'>"
This allows for non-overlapping tags that would cause errors, which also goes for JavaScript. This is what I have found over the years of programming, don't bother visiting my website to see, its messed up at the moment.
Last edited by mdshort; Dec 16, 2003 at 17:44.





Double quotes.
In php, I would use
PHP Code:echo '<img src="/path/to/image.jpg" />';


One other advantage to using single quotes in your PHP code--it parses those strings faster, since it does not need to scan them and see if there are any variables or escaped characters. Also, to make things more readable, I do not include variables in strings but instead concatonate. So, how I would put an image in is:
WWBPHP Code:echo '<img src="'.$imagepath.$imagefile.'" alt="'.$imagealt.'">'
Bookmarks