views:

95

answers:

4

I am wondering if there's a "best" approach to having a space before and after the equal sign in a HTML page when you write it down. It seems like no one is using this, but for me it seems fairly natural coming from programming languages that have this printed in their basic code style. So, is there any standard that you have to not use space before and after the equal sign of an attribute of an HTML element ?

+5  A: 

I prefer not to use spaces before and after, saves me 2 bytes per attribute. Can quickly add up 500 attributes = 1K (where 1K = 1000 bytes not 1024!)

SQLMenace
Ok, but doesn't that slow you down ? I am pretty sure that whatever application programming language you're using, even if it's javascript or whatever, you are more likely to put space before and after assignments etc.
hyperboreean
Mostly I code in SQL, in SQL I do use spaces because it is not color coded like in html, even XAML doesn't use spaces (at least by default)
SQLMenace
Note that you're not required by anyone or anything to put the exact same code on the web you're working on. Especially for Javascript minification has become common practice – nothing prevents you to do the same on your HTML.
Joey
I wouldn't go by this argument alone. The bandwidth saving should be automatically done at app publishing time by removing unnecessary white space.
Franci Penov
Re: Speed - It's really just a matter of getting used to it. I switch modes between HTML-style and JavaScript style rather smoothly now. I actually had to slow down quite a bit to type the extra spaces in my answer.
Ryan Kinal
+2  A: 

By the standards, I don't think it matters. However, I think the extra spaces make the code look cluttered.

<link rel="stylesheet" type="text/css" href="overall.css" />

looks more like a tag with name/value pairs, as opposed to

<link rel = "stylesheet" type = "text/css" href = "overall.css" />

which looks more like a string of tokens to me.

I think this largely comes from the fact that the attributes themselves are space-delimited; The end of a value and the beginning of an attribute are separated by a space, so any extra spaces only confuse things.

Ryan Kinal
+11  A: 

Not having a space delimiter between attribute name and its value actually improves the readability, as it visually shows the coupling between these. Here's an example.

No spaces delimiter:

<link rel="stylesheet" type="text/css" href="/css/screen-iphone.css" title="My Site" media="only screen and (max-device-width: 480px)" />

Space delimiter:

<link rel = "stylesheet" type = "text/css" href = "/css/screen-iphone.css" title = "My Site" media = "only screen and (max-device-width: 480px)" />
Franci Penov
+ 1 this shows clearly that spaces are confusing
SQLMenace
Shame the automatic syntax highlighting somewhat ruins the effect. :)
ig2r
@ig2r - Lol, I know... :-)
Franci Penov
+2  A: 

No one uses the spaced style simply because is easier for the eye to pick up the attribute-value pair when they are close together. The equal sign, the quotes and the fact that the attribute is always on the left and the value on the right is a clear enough visual delimiter, adding spaces breaks this effect and adds unnecessary bytes to the file.

I suggest you not to add spaces but maybe use an editor with code highlight for HTML (Notepad++ would do the trick, but I strongly suggest you to use a real editor, like Aptana Studio standalone or plugin for Eclipse).

Chepech