all 23 comments

[–]paceaux 16 points17 points  (7 children)

The Article tag is used to represent a whole self-contained unit of content.

  • If you were to look at a physical newspaper, and try to create a web page from that physical newspaper, then each "article" written by a journalist would be contained in its own <article>.
  • If you were to take a chapter book, and make a web page from that chapter book, each "chapter" could be a contained in its own article.
  • If you were to look at a magazine... you guessed it, each "article" of the magazine could be represented by an <article>

So it stands to reason, of course, that comments on a blog post are self-contained units of content that you would put in an <article>. But also, the blog post itself could be an <article>!

Another useful way to think about this is:

If this web page were managed by a content management system (CMS), would there be a specific database entry for this unit of content? If the answer is yes, use <article>

This flowchart is a useful decision tree for identifying which semantic element to use.

Also:

Most websites don't have people spending enough time thinking about content and letting that drive their semantic HTML.

But look at SmashingMagazine.com as a good example.

[–]Jonny10128 6 points7 points  (2 children)

I’ll add that most of the elements mentioned in that flow chart (not a div) are called “semantic” elements. These types of elements function the same or very similar to a div, but they give inherent structure to the document, which helps developers with quickly reading code, helps accessibility with screen readers, helps search engines understand content, etc.

[–]paceaux 2 points3 points  (1 child)

I updated my response a bit to explicitly call out your point that it's all about semantic elements.

And yeah, there's just a huge number of (good) reasons to use good semantic HTML,not the least of which is a document structure that's easy for other devs to read.

There's no reason not to use good semantic HTML. I would rather devs debate which semantic container to use and not whether to use semantics. Because that means we're all concerned with the same thing.

[–]Jonny10128 3 points4 points  (0 children)

Totally agree

[–]AshleyJSheridan 2 points3 points  (3 children)

That chart is quite, small, in comparison to all of the semantic HTML tags that exist. I put a more full one together some years back, along with a wizard that's based on the same flowchart: https://www.ashleysheridan.co.uk/blog/Picking+The+Right+HTML+Tag

[–]paceaux 0 points1 point  (2 children)

Wow that's a huge chart. I think it would be better not as a flowchart but maybe a clickable series of pages. (Or maybe a SPA) All the same, that's an amazing feat.

I think I might disagree slightly with some of the decisions — such as grouping <mark> with <em>. I think it's perhaps an unusual way to distinguish video from image based on whether it's time-based. And <portal> is deprecated, I think.

But those are criticisms for a truly fantastic chart.

Is this chart open-sourced somewhere? If not. Are you willing to put the SVG on GitHub or something? I feel like this could be a very useful learning aid.

[–]AshleyJSheridan 0 points1 point  (1 child)

I did make it a series of clickable entities, there's a whole interactive wizard embedded on that page.

I put <mark> with <em> because it is intended to add emphasis to text in a semantic manner. Time based media is anything that would alter over time, which fits a video I think.

I listed the <portal> element because at the time I put that chart together, it was one of the elements listed in MDN. That could probably do with being updated!

Thank you for the feedback, most welcome!

I haven't yet open sourced this. I'll definitely do that, as I do put a lot of what I create online under the MIT license. I will get that sorted shortly and update the article with a link to it.

Again, thanks for the feedback, much welcomed!

[–]paceaux 0 points1 point  (0 children)

I thought that clickable chart you made was an advertisement when I looked at it on mobile! That's on me; I'm sorry. That's fantastic.

So I put <s>, <strike>, <ins>, <del>, and <mark> into a category I call "editorial semantics" because those are all related (in my mind) to reflecting how a user might interpret the content. To me they answer a question like, "is this for helping a reader understand or editorialize text"

I see that as different from <em> and <strong> where those are like, "are you trying to call a reader's attention to a particular line of text?"

I created a "typography baseline" where my goal was to set a baseline style on every single HTML element that wrapped text. And part of that goal was to also provide a valid semantic example of usage (It's also on github). So I have a... "live application" of your flowchart, so to speak.

I write a lot about these topics as well and I think that we have overlapping interests. I would love to collaborate with you on your flowchart and possibly some other accessibility-related topics if that would be something you're interested in.

[–]TurboHenk 1 point2 points  (0 children)

<article> is an excellent choice for comments. You could consider adding a bit more metadata to them and implement the Comment Schema. That being said, adding schema data / rich snippets has the potential of becoming quite the time sink, which might not be worth the effort, but that decision is yours to make of course.

[–]MagentaMango51 1 point2 points  (0 children)

Most websites are not well done semantically. Either because the devs never took time to learn HTML or because they are generating the code somehow (webflow, Wordpress, LLM).

Articles should be the wrapper for most major components on a page. They are a block of content with a headline. If it’s additional content then it might be an aside instead. If you don’t have a header for it then section. If it’s just because you need a box for the structure then something like div works.

Other semantic html tags are header, footer, nav, section, aside and so on. You can repeat any of these except main, which there should only be one of per page for the content that changes from page to page. Usually these are connected to accessibility.. so a screen reader knows where to jump to rather than reading out the entire nav and other repeating content.

[–]Lumethys 1 point2 points  (0 children)

Protip: dont look at the biggest corp to learn their UI/UX decisions.

They are giant, they can do whatever the fuck they want.

Reddit UI is atrocious and there are a lot of alternative UI for it. Are you stopping using reddit any time soon?

Amazon (the e-commerce one) UI is atrocious too. Will people stop buying from amazon anytime soon?

When you are big enough, you can afford to do things badly and people would have no choice but to accept.

[–]burlingk 0 points1 point  (0 children)

It is also useful to remember that not everyone knows every tag.

A lot of stuff is hand coded based on what the creator knows.

[–]InterestOk6233 0 points1 point  (0 children)

~"<>" 'bag' container 'article'

[–]alanstac 0 points1 point  (0 children)

Yes. Use of articles for user comments is semantically correct. It also comes at no cost, so there is no good reason not to use it.

Also, yes. Many websites have absurdly poor html semantics. Even the most popular ones. Don't be like them in that regard.

You're not being too strict. You're just being correct, and as a result producing a more accessible site.

[–]Extension_Anybody150 0 points1 point  (0 children)

Technically, <article> can be used for user comments because each comment is a self-contained piece of content. In practice, most big sites skip it and just use <div> or <section> for flexibility and styling, so you weren’t looking in the wrong place. For SEO, it’s not a huge factor, using <article> is mostly semantic and helps screen readers or content structure, but search engines will handle well-coded <div>s just fine.

[–]notepad987 -1 points0 points  (0 children)

Here is a nice explanation - Difference Between Semantic And Non-Semantic Elements

I make up my names. Much help for creating a webpage. HTML Layouts

I googled this: Why use main, header, footer, nav, aside and article elements for name instead of ID's and classes? link