When is it semantically correct to use the hr element?

断了今生、忘了曾经 提交于 2019-12-03 04:45:44
daniel_gamage

It's proper to use it when you have, say, several paragraphs with two distinct themes.

<p>Paragraph about domestic kittens</p>
<p>Paragraph about kittens' favourite foods</p>
<p>Paragraph about kittens' playfulness</p>
<hr>
<p>Paragraph about my day at work</p>

If you'd like to otherwise separate themes among images and content, I believe this is also appropriate.

<img src="/img/kitten.jpg" alt="kitten playing with ball">
<img src="/img/kitten1.jpg" alt="kitten drinking milk">
<hr>
<img src="/img/zebra.jpg" alt="zebras in the wild">

The new use of hr seems to just be for distinguishing topics within HTML. If you find that your content is well-connected, don't feel that you need to use the tag.

According to this article

In HTML 4.01, the <hr> tag represented a horizontal rule.

In HTML5, the <hr> tag defines a thematic break.

However, the <hr> tag may still be displayed as a horizontal rule in visual browsers, but is now defined in semantic terms, rather than presentational terms.

All layout attributes (align, noshade, size, and width) in HTML 4.01 was deprecated in HTML 4.01, and is not supported in HTML5. Use CSS to style the <hr> element instead.

In HTML5, use <hr> when you are diverting your topic from the previously written paragraph.

My short answer and the way I've gone about it is that I use <hr>'s when there is just no other way for it to be done cleanly with CSS. For me this has translated into many years of writing html and never having to use an <hr>.

Eventually, I could see myself using an <hr> if I am just trying to put some kind of marker between two sections of the same content.

Using an example of a blog post: I would put an <hr> when I I feel it's visually important to transition from one topic to another.

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