I came across the following article which suggests the _header, section, article, footer_ tags in html5 should not be used for styling content… therefore classes/ ids should not be used to target css. The article is dated 2011, so Im curious if the suggested practice has changed at all. I continue to see other sites using classes and ids on the mentioned tags.
If anyone as any ideas or can suggest an updated article stating otherwise… I would much appreciate it. Thank you.
I’m not really sure I’m following how you mean. Admittedly I just glanced through it this time, but I didn’t get the impression that he advocated against using them for styling content, and I certainly didn’t get the impression he suggested not to use classes/ids to target CSS.
My impression of the article is that they should not be used as wrapping-elements, ie this: If you look at an element, it has no semantic meaning, but you need something to contain something else (for backgrounds, for borders, for floats, for whatever), then use a div rather than section/article/footer/header.
Also, be careful when targeting header/footer directly, since they are explicitly allowed to be in several places, so it might lead to unexpected side-effects.
I think that the best practices currently is to set classes on them and target them through that.
Now I’m not sure how you mean @HugoGiraudel, so I think I want to get a bit more details =)
Yes, I style both h1 and p tags directly: I set margins, font-sizes, occasionally line-heights, font-family… Do you mean something else when you say they shouldn’t be styled directly? (Note that my confusion/disagreement is not with div/span, but rather with p and headings)
Well, it’s probably because it’s a bit of a grey zone, and people don’t always read up on best practices. Generalised, yes, the second method is the correct one. Where it would probably be less correct is the following case:
In the above case it’s probably a better idea to just put the class “wrapper” on the section.
@melinda Thanks for the reply, but your example seems to contradict my previous post. All I’m looking to know is whether classes / ids can be used on the section tag or if they are simply used for semantic reasons as @unasaquila suggests. It’s not rocket surgery.