href syntax : is it okay to have space in file name

Moon picture Moon · Nov 13, 2010 · Viewed 81k times · Source

it has always been my practice that when ever i use images i name them like walls_ico , bu_hover

so when i give paths they go like

<img src="images/walls_ico.ico" />
<img src="buttons/bu_hover.png" />

UNTIL now when i am on a project where users upload files...

i was wondering is it okay to have spaces between file and folders name like

<img src="buttons/bu hover.png" />

Answer

Fr&#233;d&#233;ric Hamidi picture Frédéric Hamidi · Nov 13, 2010

The src attribute should contain a valid URL. Since space characters are not allowed in URLs, you have to encode them.

You can write:

<img src="buttons/bu%20hover.png" />

But not:

<img src="buttons/bu+hover.png" />

Because, as DavidRR rightfully points out in his comment, encoding space characters as + is only valid in the query string portion of an URL, not in the path itself.