Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spaces before and after the `=` sign of HTML element attribute

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 ?

like image 824
hyperboreean Avatar asked Aug 23 '10 20:08

hyperboreean


2 Answers

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)" />
like image 70
Franci Penov Avatar answered Oct 24 '22 09:10

Franci Penov


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.

like image 8
Ryan Kinal Avatar answered Oct 24 '22 10:10

Ryan Kinal