Die, Heretic!
Consistently putting quotes around attribute values — even when doing so isn’t required — is:
- A practice worthy of ridicule
- Harmless
- Best practice
- Compulsory
It’s just data
Consistently putting quotes around attribute values — even when doing so isn’t required — is:
Waffling between C and D. Interestingly, on the Planet Sysadmin blog aggregator, the list was rendered with numbers rather than letters. In that case, waffling between 3 and 4.
Posted by Alex Elsayed atAbsolutely, D.
Posted by Bob Aman atAlex: The lower-alpha switch was set in an inline style element, which was likely stripped for security reasons.
Posted by Bob Aman atAll of the above.
Posted by Christian Romney atIt can’t be D - “required” and “compulsory” are synonyms.
Surely C (and B).
Posted by Sam McCall atI’ll go for C (-b), if only because the one option I want is not listed:-).
I use quotes because it makes my code more easy to read, especially in quickscan mode, as it triggers a colour change in my text editor..
Leaving all issues of XML-fu aside, omitting quotes does make life trickier for the legendary DPH (desperate perl hacker), who needs to write a quickie script to change all instances of something to something else in a few thousand documents by 4PM. It’s a dirty little unsecret that it’s perfectly possible to do ad-hoc processing of most real-world XML using Perl or Ruby or whatever, never involving an XML processor. But if you start allowing eccentric “HTML as she are spoke” syntax variations, not so much.
Posted by Tim atI like having the option to omit quotes. I also prefer <i> and <b>.
[Tom:] So I take it you’re okay with single quotes and double quotes?
Sometimes I wish I could put attributes in the closing tag. Sometimes it’s just handier to generate XML like that because I just wasn’t ready when the opening tag occurred. I needed more time.
Imagine: <table><tbody><tr><td>Single celled tables need love, too.</td></tr></tbody></table border=1>
Posted by Julius Davies atWhoops. You’re a Tim, not a Tom. Sorry about that.
Posted by Julius Davies atI’ll gladly be the first to declare A/B, at least for attributes that you’re writing by hand. Though if I’m using multiple CSS classes on elements in a template, I’ll usually use quotes just to be consistent.
For generated attributes, I do use quotes, just because having to escape using numeric entity references feels gross. Why is there no character entity reference for the normal space character?
Posted by Fred Blasdel atI’d say “a matter of personal choice” (hence my suggestion, which Ian accepted this week, for the spec not to take a position on this), So I guess B is the closest.
Ridiculing their use is unreasonable: there are people (and automated generators) who prefer the simplicity of always including them, for example so they can use XML tools or not have to remember the rules about when they are compulsory.
But equally if you’re authoring by hand and you know the rules — or you’re using a generator which cares about squeezing pages to the fewest bytes — then including them is a burden with no benefit.
The forms are isomorphic, and it’s trivial to automatedly convert between them, so anybody who has a strong preference one way can easily cope with HTML written t’other way without getting dogmatic about it or trying to promote their preference as being the ‘right’ one.
Posted by Smylers atI’d go with D. While authoring by hand I don’t really like to think about whether I need them or not. Maybe I’ll need them in the future anyway (adding another class, etc.).
Posted by Tenno Seremel atSomewhere between b and c. There’s still too many people out there creating websites for whom it’s the closest thing to c, and so for whom it really should be d, for me to want to choose a. :)
Posted by Sander atWell, the current HTML standard seems pretty clear:
We recommend using quotation marks even when it is possible to eliminate them. (HTML 4.01, section 3.2.2)
That sounds like “best practice” to me.
Posted by Joe Pallas atWhile I write I prefer to omit them, but when I read I prefer to see them. I can’t help – it’s just more legible to me than just a single equals sign. So I choose (b).
Posted by Tori atc (d)
because that way it looks more XML-ish
it’s easier not to have to remember two things - XML and HTML
for this reason I would often close ‘p’ and ‘li’ tags too
It’s always required for me because I author XHTML and SVG, but taking your question in the spirit it was asked, I’ll say C.
Posted by Jeff Schiller atB, without a doubt.
I’m all with Smylers.
(Sam, did you mean “compulsive” rather than "compulsory"?)
Posted by Thomas Broyer atSomewhere between A and B - call it “slightly harmful”. (Assuming we are talking about HTML generated for the web.)
Every extra byte means more CPU cycles on the server, and a bit more traffic crossing the web. This has a (small) cost in terms of overall performance, and in energy use. That’s right - extraneous quotes add to Global Warming!
The receivers have to parse HTML as it exists in real life. HTML parsers are only going to become more plentiful, and more easily re-used. Given equivalent function, fewer bytes on the wire is a good thing.
Posted by Preston L. Bannister atI’d have to say it’s been a best practice for me to always quote attribute values since the turn of the last century. Especially since I’ve actively advocated (and mostly used) “proper” XHTML over the years. I simply find that it makes my code more easily readable.
Given the nature of HTML5 I’d say that it’s a harmless practice for anyone continue doing it as long as “dual serialization” is a part of the HTML5 concept.
So C + B is my humble opinion.
OT:
Sorry, Preston, but I personally don’t buy the “global warming” argument since most of us still litter our sources with spaces, newlines, tabs and so on and won’t think twice about how well optimized our PNG:s are or many extra HTTP requests it takes to utilize “that nifty Web 2.0 effect” from our framework of choice - unless our host slaps us with an “exceeded traffic” bill ;)
If we really wanted minimal transfer packages, we should all look back to WAP 1 and incorporate the binary transfer formats of that concept - i.e. the compiling “middle station” sending binary optimized code to the user agents - into “the modern web” instead of continuing to send marked up text “all the way” ;)
And no - I don’t think that’s the best of ideas for HTML5 at this point either :) !
Posted by Jarvklo atIt’s much easier to teach somebody to always quote than it is to teach somebody the rules where quoting is necessary. Attempting the latter results in many invalid pages followed by a switch to the former. Optional quotes are a needless complexity and from an authoring point of view it is better to pretend they are mandatory.
Posted by Jim atD D D D D! Then again, I’m also an obsessive whitespace ninja and will often make changes to projects I work on that simply reformat whitespace to a consistent norm (mine). So, uh... take that with a grain of salt. ;)
Posted by Travis Tilley atMandatory (d) best practices (c) for teaching (class of products) ;)
Posted by karl dubost atThat’s right – extraneous quotes add to Global Warming!
Someone once calculated that the fact that Google’s pages have a white background instead of a black one ends up consuming a power plant’s worth of energy world wide. (I suppose that is no longer true in the same way in this era of LCD-type screens.)
Worrying about the minuscule effect of quotes on the climate is either misguided or an attempt to rationalise a preconceived preference about them.
Posted by Aristotle Pagaltzis atFunny story:
When I was learning HTML, 15 years ago, I did it, as we all did in those days, by viewing source. I don’t think I ever saw a closing </P> tag. Ever. It never occurred to me that <P> was an element that contained text. Rather, I surmised, it was an element that inserted a blank line in your text, much as <BR> inserted a horizontal rule.
Eventually, I learned that <P> did contain text, but that the closing tag was “optional” and, in the absence of an explicit </P> tag, the end of the <P> element was determined by some complicated set of rules. I immediately decided that learning and remembering that set of rules would impose a far-larger cognitive burden than inserting the four extra bytes. So I took to conscientiously using </P>.
I tend to feel the same way about quoting attribute values. Is it really worthwhile learning and remembering the rules for how unquoted values are delimited?
Posted by Jacques Distler atC, because it makes me feel better. With a perfect parser, I guess it doesn’t matter. But, with a buggy one, I always feel like it’d get quoted attributes right more than unquoted ones.
Posted by Michael A. Puls II at@Jacques, and you would not be wrong. It is part of the history of P. The semantics of the element changed in 1994.
In Toward Closure on HTML, Dan Connolly said:
But I would like to introduce one change to the way P elements work: I’d like to make the P element a paragraph container rather than a paragraph separator. The only required change is to put a <p> tag at the beginning of every paragraph — we can use the OMITTAG feature to make </p> tags implicit. It makes for a much cleaner DTD in many ways, and it just makes more sense.
Thanks, Karl. You really should issue a "Spew Alert" warning, before expounding on the history of HTML.
My keyboard will thank you.
Posted by Jacques Distler atJacques, the best part of the email is this paragraph.
Outstanding Issues in HTML: The current working specification for HTML[9] does not faithfully represent contemporary practice as supported by applications such as Mosiac and Lynx. Nor do those applications give a precise definition for HTML.
15 years ago. We hear the same thing about html4 now. :) I’m impatient to see 2022. ;)
Posted by karl dubost atKarl, that paragraph is priceless.
(And for the original post, though I’m just an HTML hobbyist I’ll go with C.)
Posted by Micah Sittig atSteven Pemberton: I must say that this discussion reminds me of this passage in the Through the Looking Glass: ‘When I use a word,’ Humpty Dumpty said in rather a scornful tone, ‘it means just what I choose it to mean...
[more]
Trackback from Sam Ruby
B.
Posted by Geoffrey Sneddon atE. Annoying.
Posted by Giulio Piancastelli atIt is C, and should be D.
The looseness of HTML gives rise to a number of problems that you don’t find in regular programming languages.
Some say it’s a pain, but it’s not something I actively notice. I code everything — anything ever — by hand, and I always put every value in quotes (usually double-quotes, unless something happens in a script).
I think development tools just make people lazy. I can’t stand to use them, myself, because I have to go through the code afterwards and fix everything up.
Posted by Michael Kozakewich atC and should be D.
Even before XHTML got popular (and long before I knew anything resembling a programming language), I had started quoting all of my attributes and closing paragraphs. I hadn’t starting closing things like img or br, because I’d never heard of a way to do so.
I did that because I felt that following 1 rule all the time was far easier than remembering exceptions.
It’s like the english language--I always hear it’s hard to learn because there are rules that seem contradictory which apply in different contexts. Just looking around, even native speakers can’t remember whether it should be “lie” or “lay” and when to use an apostrophe. I’m pretty good with language on an instinctive level, yet I make grammatical mistakes every day.
It’s a fact: keeping a language simple makes it easier to read and to write without making mistakes. In HTML most mistakes are not fatal, but I still think it’s a waste of time and energy to complicate markup with exceptions...
These days I program enough to understand the other benefits. Closing all tags and quoting all attributes results in a regular, predictable pattern which is far easier to parse. Saving 3 bytes by omitting </p> doesn’t make up for the extra contextual processing I presume is necessary to support irregularly formed markup (keeping in mind all the things that have to interact with a document and deal with those exceptions: the browser’s layout engine, building a DOM, the javascript engines, CSS, et cetera).
Of course, since HTML got popular as tag soup the browsers and all handle it transparently. Enforcing XML syntax rules is kind of a case of hindsight being 20/20 IMO. The workarounds are already in place, but it would have been a nice had they never been necessary. (Functionality suggests that browsers simply ignore </p> as far as rendering empty lines is concerned, often the whole point of using the paragraph tag.)
So the horse is out of the barn; that doesn’t mean we shouldn’t close the barn door now. The foal is still inside.
Posted by Rhy atI propose a new acronym: KICK, “keep it consistent, knucklehead”. Do either all enclosed in quotes or none. As for myself, I’ve been avoiding the quotes just 'cuz I don’t like them. However, on reflection I’m going to switch to all quotes, all the time.
Posted by Matt atI would say it’s "mostly harmless"! :)
Posted by Phil at