[英]Are XHTML tags valid in HTML?
I understand a line break in HTML is <br>
and the XHTML equivalent is <br />
. 我理解HTML中的换行符是
<br>
,而XHTML等价物是<br />
。
I know that you cannot use the above HTML tag in a XHTML document, but what about vice versa? 我知道您不能在XHTML文档中使用上面的HTML标记,但反过来呢? Is
<br />
valid in HTML? <br />
在HTML中有效吗?
It depends which version of HTML you are talking about. 这取决于您所讨论的HTML版本。
In the latest stable version, HTML 4.01 , the syntax means the same as <br>>
which means the same as <br>>
在最新的稳定版本HTML 4.01中 ,语法与
<br>>
相同,这意味着与<br>>
相同<br>>
. 。 This means it is valid, since you can have a
>
anywhere you can have a line break, (although <meta />
usually isn't valid) but doesn't mean what you want. 这意味着它是有效的,因为你可以有一个
>
的任何地方,你可以有一个换行符,(虽然<meta />
通常是无效的),但并不意味着你想要什么。 Limitations in browsers (exploited by the XHTML 1.0 spec) mean that it gets treated as <br>
even though it shouldn't be. 浏览器的限制(由XHTML 1.0规范利用)意味着它被视为
<br>
即使它不应该。 The mess around this feature means it is marked as to be avoided . 围绕此功能的混乱意味着它被标记为要避免 。
HTML 5 changes that and turns the /
into syntactic sugar. HTML 5改变了和原来的
/
到语法糖。 Utterly meaningless but allowed so the XML junkies are kept happy. 完全毫无意义但允许XML迷们保持高兴。
<br />
is backwards compatible and will not cause rendering problems if used in an HTML document. <br />
向后兼容,如果在HTML文档中使用,则不会导致渲染问题。
Also, note that unless you are serving your documents with the MIME type application/xhtml+xml
, putting a <br>
in an XHTML document won't cause it to choke. 另请注意,除非您使用MIME类型
application/xhtml+xml
提供文档,否则在XHTML文档中放置<br>
不会导致它被阻塞。 It is a validation error to leave a BR unclosed in an XHTML document, but a very minor one which is unlikely to cause any problems by itself. 将BR封闭在XHTML文档中是一个验证错误,但这是一个非常小的,不太可能导致任何问题。
EDIT: Oh yes, and in HTML5 the closing /
is once again officially optional. 编辑:哦,是的,在HTML5中,结束
/
再次正式可选。
<br />
is valid HTML. <br />
是有效的HTML。 Some HTML pages may be generated by an XML engine that can't outpout <br>
, and as such it must be able to parse it. 某些HTML页面可能由不能outpout
<br>
的XML引擎生成,因此它必须能够解析它。
Yes XHTML is compatible with HTML. 是的XHTML与HTML兼容。
I believe there is one exception in HTML5 which is processing instructions like <?xml...>
have been deprecated. 我相信HTML5中有一个例外,即
<?xml...>
等处理指令已被弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.