The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,177 other subscribers

HTTP protocol requires you to escape spaces (usually with %20 or with +), but web-browsers will do that for you

Posted by jpluimers on 2014/02/20

Since the time that spaces are allowed in path and file names, it has caused confusion.

I personally like the readability of  spaces, but still tend to avoid them as they usually cause more harm than the readability gains.

An interesting thread about spaces in file names is operating systems – What technical reasons exist for not using space characters in file names? – Super User.

In URLs, you there are various kinds of places where spaces can be used. You have to escape as Xah Lee wonders in does HTTP protocol require space be encoded in file path?.

The escaping is part of the URL Encoding, but the escapes depends on the position of the space. In the query part (after the first ?), you can have it escaped by both %20 and plus sign, but in the path part (before the first ? sign), it can only have a %20.

This is explained by bobince in urlencode – when to encode space to plus (+) and when to %20? – Stack Overflow.

That escaping basically makes path and file names a lot less readable when passed as a URL. It causes posts like these:

But why can you still use spaces when you type a URL in your web browser, or use it in a href, src or other HTML URL attribute?

Xah Lee rightfully earlier wondered about that in webserver – space in url; did browser got smarter or server? – Stack Overflow.

Technically, both are not allowed. But web browser manufacturers understand we humans are lazy, and accommodate for that by encoding these when putting them into the HTTP request.

You can type “ bar” in your web browser, and depending on the browser, it gets translated into either one of these:


  • encode spaces in URLs as %20
  • try to avoid spaces in path and filenames



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: