开发者

Is it good practice to have 'naked' text in html?

开发者 https://www.devze.com 2023-02-04 08:53 出处:网络
Wasn\'t sure how to express this but what I mean is h开发者_JAVA百科aving things like <h1>My name is</h1>Radu as opposed to <h1>My name is</h1><p>Radu</p>. Obviousl

Wasn't sure how to express this but what I mean is h开发者_JAVA百科aving things like <h1>My name is</h1>Radu as opposed to <h1>My name is</h1><p>Radu</p>. Obviously not the best usage of the h1 element but I think that can be excused. So, should all HTML be wrapped by the appropriate tags?


No, it's not really good practice. In practice, it probably won't hurt, but it's technically "wrong", since the HTML spec doesn't permit naked text in the body. Browsers will forgive you and generally wrap them up in some other element (if you inspect the DOM tree using Firebug or something).

In XHTML it is completely forbidden.


All text is "wrapped in" the <body> tag. There's no reason why it has to be wrapped any further. In your example, you're actually changing the "semantics" of the page by adding the <p> block; whichever one expresses what you want is correct.


Depends on the DOCTYPE

generally "best practices" are determined by the W3C and their validator service, if it passes validation for your intended DOCTYPE, I say you're good to go. Many of the "Higher Level" DOCTYPEs require that most/all text nodes be wrapped in some form of DOM node.

0

精彩评论

暂无评论...
验证码 换一张
取 消