Reputation: 8105
According to RFC3986:
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
So no space-encoding required here.
Only Appendix C talks about whitespace but only talks about URIs that are placed e.g. in plain text where space can be used to seperate different urls. This is imho not the case if placed in src
attributes.
Nevertheless nearly every tutorial about "url encoding" starts by telling that space is encoded by %20
. (Or + or mixed combinations of both or ...)
Upvotes: 2
Views: 794
Reputation: 700152
Space is not a reserved character in an URI, because there are no spaces in an URI.
If you have an identifier that contains a space, you have to encode the space when you put it in the URI. The encoding is not to satisfy HTML syntax, it's to meet the standard for an URI.
Related: Is a URL allowed to contain a space?
If you use spaces in an URI in the HTML code, the browser has to encode the space for you to use the URI to request anything. This is just the browser protecting you from yourself, and AFAIK all current browsers do this, at least in most situations. It's still better to do it correctly, than to rely on the error correction in the browser.
Upvotes: 2