Mobile app version of vmapp.org
Login or Join

Login to follow query

More posts by @Kaufman445

4 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

In (X)HTML5, the a element’s href attribute


[…] must have a value that is a valid URL potentially surrounded by spaces.


As the anchor suggests, it may contain leading and trailing spaces.

The linked section makes clear that these spaces will be stripped:


[…] the user agent must remove all space characters that are at the start or end of the string […]




If the actual URL starts/ends with (or contains) spaces, you have to percent-encode them with %20.

These elements have different URL values:

<a href=" foo">…</a> <!-- the URL is <foo> -->
<a href="%20foo">…</a> <!-- the URL is < foo>, i.e., <%20foo> -->


These elements have the same URL value:

<a href="%20foo">…</a>
<a href="%20foo ">…</a>
<a href="%20foo ">…</a>
<a href=" %20foo">…</a>
<a href=" %20foo">…</a>
<a href=" %20foo ">…</a>

10% popularity Vote Up Vote Down


 

@Jessie594

Yes, it will be automagically corrected by the browser ,anyway if using spaces you get an error you can write them in another way:

a URL, so a href, supports spaces, just replace them with "%20"
Anyway if you write

<a href="%20#id"> </a>


This will result in a " #id " and not "#id"

Eg:

<a href="?How%20Are%20You">How are you?</a>

10% popularity Vote Up Vote Down


 

@Smith883

You can run your markup through the validator yourself to find out if what you wrote is valid. But valid markup is not always an indication of valid transport and spaces must be URL encoded (and the hash mark also).

You can learn more by searching Stackoverflow. In particular, this SO answer. Your characters are not safe to use.

10% popularity Vote Up Vote Down


 

@Berumen354

Why would you do this? Who writes code like that? That's unnecessary space in between "".

Literal spaces are not allowed in URLs and they are not part of the data. just formatting for human consumption.

You need to remove the whitespace. Some browsers render it as a space.

Spaces are valid. And they both are different because, one has spaces, other doesn't. That means, that formatting or link is different.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme