Is the "href" attribute of an attribute element needed?

I checked the HTML code on my web page and validated it using the Firefox HTML Validator add-in , and I saw that it complains about the href the link attribute, which contains Unicode characters that are not URL encoded.

Current URL:

 <a href='/اخبار'>Persian News</a> 

However, the validator wants it to be:

 <a href='/%D8%A7%D8%AE%D8%A8%D8%A7%D8%B1'>Persian News</> 

I tested this link in almost every browser (even in IE6). It works great. So what is the problem? Why code it? Is the validator obsolete? What kind of problem might result from not encoding the Unicode character url inside the href attribute of the href tag?

+4
source share
4 answers

URLs can only be sent over the Internet using the ASCII character set.

Usually the browser performs the encoding for you.

+4
source

Browsers that do not support this language (encoding) will not be able to open the URL. You must encode it so that everyone can use the full functionality of your site.

+3
source

Yes, I tested this with <meta http-equiv="Content-type" content="text/html; charset=windows-1251"/> which means for Russians, and the link just turns into <a href="/?????">Persian News</a> so you need the right encoding and encoding for it to work properly.

+1
source

It depends on which standard you want your page to conform to:

  • For (X) HTML5, URIs containing non-ASCII characters (i.e. IRI) are valid if your document is encoded in UTF-8 or UTF-16 and the MIME headers are sent accordingly.

  • In HTML4 / XHTML1 documents, all non-ASCII characters must always be escaped.

See also the answer to Are IRIs valid as HTML attribute values? .

0
source

Source: https://habr.com/ru/post/1379092/


All Articles