Are IRIs valid as HTML attribute values?

荒凉一梦 提交于 2019-12-05 04:21:49

HTML 4.01 is straightforward enough. Different attributes have different rules as to what they can contain, but if we're dealing with the href attribute on an <a> element, then the HTML 4 spec, section B.2.1 Non-ASCII characters in URI attribute values says:

... the following href value is illegal:

<A href="http://foo.org/Håkon">...</A>

HTML5 is different. It says IRIs are valid providing they comply with some additional conditions.

A URL is a valid URL if at least one of the following conditions holds:

  • The URL is a valid URI reference [RFC3986].

  • The URL is a valid IRI reference and it has no query component. [RFC3987]

  • The URL is a valid IRI reference and its query component contains no unescaped non-ASCII characters. [RFC3987]

  • The URL is a valid IRI reference and the character encoding of the URL's Document is UTF-8 or a UTF-16 encoding. [RFC3987]

XHTML 1.x follows the same rules as HTML 4.01.

XHTML5 is the same as HTML5.

When in doubt, read the official HTML specs for definitive answers.

HTML 4 does not support IRIs at all. They must be encoded as URIs per RFC 3987 Section 3.1, or encode non-ASCII URI data as UTF-8 with percent encoding per HTML4 Section B.2.1

HTML 5 supports both URIs and IRIs in all places where URLs are allowed, per HTML5 Section 2.6.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!