Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2004, 01:46 AM   PM User | #1
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
Why do we use " instead of ' ?

First off, I've always used " as I believed it was the only option. Now I'm working with a C++ guy who uses ' instead. I told him it wouldn't validate, but it does?? (I didn't check his doctype however..)
I did a little investigating at the good 'ol W3C and found although they accept both, ALL W3C examples are shown with ".
In another thread, both Skyzyx and me' insisted that XHTML dictates the use of " for all attributes. Now I'm not doubting either of these guys as I've learnt a fair bit from both, but why???

I'd really like to see some kind of official documentation or just reasoning that I'm not aware of 'cause this one's been floating round in my head for a week or two.
__________________

I take no responsibility for the above nonsense.


Left Justified
mindlessLemming is offline  
Old 01-05-2004, 01:51 AM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
As long as you quote attributes (with ' or "), it really doesn't matter. De facto standard is ". " seems to make the values stand out for me anyway. But they're both equally valid, I'm pretty sure.
__________________
jasonkarldavis.com
jkd is offline  
Old 01-05-2004, 04:21 AM   PM User | #3
Skyzyx
Regular Coder

 
Skyzyx's Avatar
 
Join Date: Aug 2002
Location: Silicon Valley, CA
Posts: 980
Thanks: 0
Thanked 0 Times in 0 Posts
Skyzyx is on a distinguished road
Yes, both are perfectly valid. However, I generally recommend using double-quotes in (X)HTML because that's how the majority of HTML code and documentation is written.

Also, I tend to use single-quotes in JavaScript, and it helps me differentiate easily between the two.

The most important thing is to be consistent and get a style going.

The point that I was making in that other thread was that all attributes needed to be quoted in the first place. The guy I was trying to help hadn't quoted hardly anything at all, and was wondering about validation errors.
__________________

Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

Last edited by Skyzyx; 01-05-2004 at 04:23 AM..
Skyzyx is offline  
Old 01-05-2004, 04:59 AM   PM User | #4
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
Well, just my two cents, but when someone suggests quoting something, the first thing that comes into my head is "." So, I guess there's reasoning enough, structure attribute quotes in the same manner you would in everyday life.

<<Unless, of course, you're from overseas and use another form of punctuation,>> I replied.

-Rich
__________________
drums | web
rmedek is offline  
Old 01-05-2004, 11:29 AM   PM User | #5
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
Quote:
Originally posted by rmedek
<<Unless, of course, you're from overseas and use another form of punctuation,>> I replied.
Good point, but we have ways of getting round this.

I didn't realise you could quote attribute values with ' myself, so I popped over to the w3c and had a look. After a few minutes of searching (jeez, you gotta hate the XML spec), I found it:
Quote:
The Name in the start- and end-tags gives the element's type. [Definition: The Name-AttValue pairs are referred to as the attribute specifications of the element], [Definition: with the Name in each pair referred to as the attribute name] and [Definition: the content of the AttValue (the text between the ' or " delimiters) as the attribute value.]Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.
[quote source]]

Well, there you go. I've never thought of using ", and I don't think this'll change things, but if you feel more comfortable this way, why not!?

*goes back and edits other thread*
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline  
Old 01-05-2004, 07:50 PM   PM User | #6
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
i tend to prefer using the double quotes, unless i'm outputting the code via PHP, and i'm too lazy to go round espacing all my double quotes...
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline  
Old 01-06-2004, 03:35 AM   PM User | #7
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Readme, you're supposed to use double quotes for strings really. Seeing as PHP is a C scripting language and in C 'a' would be 96 ( I think ) and "a" would be a ... It's just wrong in my oppinion to use ' for strings greater than 1 character in length ..
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline  
Old 01-06-2004, 12:20 PM   PM User | #8
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
Quote:
Originally posted by me'
Good point, but we have ways of getting round this.
Thanks for that one me'.
__________________

I take no responsibility for the above nonsense.


Left Justified
mindlessLemming is offline  
Old 01-06-2004, 04:46 PM   PM User | #9
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
Quote:
Originally posted by mindlessLemming
Thanks for that one me'.
I should point out that the support for :lang is extremely poor, so I'd use:
Code:
html[xml:lang|="fr"] span.example { quotes: "«" "»" }
where the support is slightly better (moz, op off the top of my head)
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline  
Old 01-08-2004, 07:44 AM   PM User | #10
briintex1
New Coder

 
Join Date: Dec 2003
Location: texas
Posts: 96
Thanks: 1
Thanked 0 Times in 0 Posts
briintex1 is an unknown quantity at this point
the " vs. the ' '

I do know in the C++ language that the double quotes are used for strings and the signle quotes are used for a character for instance it would be a good thing to use for a menu. I do not know if that is one of the answers you are looking for, or I might have hit it way way off...
__________________
thanks
bri
briintex1 is offline  
Old 01-08-2004, 01:03 PM   PM User | #11
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
The C or PERL (and later scripting languages using the same idea, such as Ruby, PHP etc.) difference between single and double quotes does not in any way affect SGML, XML or HTML. Neither of these do any differentiation between them. In fact, SGML is really lax and allows the language to specify other quoting characters if you want them.

However, there are some rather good reasons for why you should use double instead of single quotes:
- English language as well as many other languages uses single quotes (or apostrophes really, but ASCII doesn't differentiate those two characters) in regular writing, which means that you can't enclose such writing in single quotes without prematurely closing the string. Since SGML/HTML/XML character escaping is rather wieldy, you may want to avoid it altogether, by using a character not present in regular writing for string delimiter.
- JavaScript may also use either single or double quotes for strings, but unlike SGML/HTML/XML character escaping, the JavaScript character escaping is small and makes the raw string only marginally less readable, which is the reason JavaScript traditionally uses single quotes. If we use double quotes for SGML/HTML/XML strings, that makes enclosing a single quoted JavaScript string in for example event handlers that much easier.
- XML makes quoting strings necessary, but HTML is laxer and doesn't need it unless the attribute contains a space (parsers ignore that it should only be numbers that are allowed to be unquoted, really). As a preparation for XML and because it makes the code look nicer, you should use some quoting character for HTML strings even for numbers.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline  
Old 01-08-2004, 04:19 PM   PM User | #12
hrp2171
New Coder

 
Join Date: Dec 2003
Location: Central California
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
hrp2171 is an unknown quantity at this point
Yeah, single and double quotes are interchangeable.

But it will probably become more clear as to why when working with JavaScript.

Example:

Code:
onclick = "document.location('http://www.google.com')";
Here I could've started with the single quotes, but the inner quotes would've been double. And vice versa!
__________________
/hector/rooted/@/a/puter
hrp2171 is offline  
Old 01-08-2004, 04:28 PM   PM User | #13
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Ok I think this thread has achieved it purpose (possibly several posts back) and the same thing has been essentially said by a whole bunch of different people time to close this all you can post buffet.
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:54 AM.


Advertisement
Log in to turn off these ads.