If I put a div as a parent to semantic tags, will this div cancel the semantic properties of those tags?

If I put a div as a parent to semantic tags, will this div cancel the semantic properties of those tags?

Welcome to the forums!

Not strictly no, the idea of a semantic tag is to convey important information about what that tag contains, to make it easier to read the code (and for accessability purposes for example with screen readers). If you were to have, let’s say, a <div> tag around an <article>, it would still be clear to anyone reading the code that whatever was contained in that tag was part of an article, regardless of the parent tag. By nature of having lots of nested tags however, it might have the side effect of making the code a little less readable, but that may be the case regardless of whether or not semantic tags were used.

That being said, it’s generally better to use semantic tags in most situations. I would say that it’s quite possibly better to use a semantic tag instead of that <div>, perhaps something like a <section> or <article> (but which one to use, and whether it should be used in the first place depends on your code)

3 Likes