Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 - Appropriate use of Article Tag?

Tags:

html

I want to change

<section>   <header>...</header>   <p class="tweet">This is a tweet preview. You can... <em>6 Hours ago</em></p> </section> 

into

<section>   <header>...</header>   <article class="tweet">     <p>This is a tweet preview. You can... <time pubdate>6 Hours ago</time></p>   </article> </section> 

But after reading some articles on the <article> tag, I'm not sure that this is the best move. What would be better practice?

like image 560
Wex Avatar asked Aug 04 '11 19:08

Wex


People also ask

What is the use of article tag in HTML5?

The <article> tag is one of the new semantic elements introduced with HTML5. According to the HTML5 specification : The article element represents a section of content that forms an independent part of a document or site; for example, a magazine or newspaper article, or a blog entry.

What do we use article tags for?

Definition and Usage. The <article> tag specifies independent, self-contained content. An article should make sense on its own and it should be possible to distribute it independently from the rest of the site.

Should I use article or section?

Articles are mostly but not compulsorily used in Constitution whereas Sections are being used in Acts. For example, Indian Contract Act, 1872 is divided into 266 Sections and each Section defining different topic. Article is independent, that is, it is mostly self-explanatory.

What is a tag in an article?

Tags help us identify what an article's about and present better results to your users. Tags are especially helpful when your users refer to features by many different names. For instance, we have custom HTML templates. A user might type html, custom html, template, theme, layout, etc. to find that article.


1 Answers

The important thing to understand about articles and sections is that they are sectioning elements. Each follows a common pattern:

<sectioning_element>     <heading_or_header>     ... the body text and markup of the section     <footer> </sectioning_element> 

The footer is optional. Sectioning elements should have a "natural" heading. That is, it should be easy to write an <h?> element at the start of the section/article, that describes and summarises the entire content of the section/article, such that other things on the page not inside the section/article would not be described by the heading.

It's not necessary to explicitly include the natural heading on the page, if for example, it was self evident what the heading would be and for stylistic reasons you didn't want to display it, but you should be able to say easily what it would have been had you chosen to include it.*

For example, a section might have a natural heading "cars for sale". It's extremely likely that from the content contained within the section, it would be patently obvious that the section was about cars being for sale, and that including the heading would be redundant information.

<section> tends to be used for grouping things. Their natural headers are typically plural. e.g. "Cars for Sale"

<article> is for units of content. Their natural headers are usually a title for the whole of the text that follows. e.g. "My New Car"

So, if you're not grouping some things, then there's no need, and it's not correct, to use another sectioning element in between the header and footer of the section and your correct mark-up would be

<article class="tweet">   <header>...</header>   <p>This is a tweet preview. You can... <em>6 Hours ago</em></p> </article> 

assuming you can find a natural heading to go inside the <header> element. If you can't, then the correct mark-up is simply

<p class="tweet">This is a tweet preview. You can... <em>6 Hours ago</em></p> 

or

<div class="tweet">      <p>This is a tweet preview. You can... <em>6 Hours ago</em></p> </div> 

* There's a case for including the natural heading anyway, and making it "display:none". Doing so will allow the section/article to be referenced cleanly by the document outline.

like image 84
Alohci Avatar answered Sep 26 '22 08:09

Alohci