htmltextbrowserseocompatibility

Is a text inside <div> tags semantically correct


Most of us have seen something like this before:

<div class="rights">All rights reserved!</div>

I just wanted to know, is this a right job? or althogh it will render in browser, it is better to use <p> tag for example?

I am asking this to know if it has any Google(SEO), HTML Validity, ... issues/downsides.

Both div and p are block level elements. So, what is the reason to have a p tag in HTML, when div exists?


Solution

  • After more than 10 years, I want to answer my own question and share part of my knowledge and experience.

    Using text directly inside div tags is not semantically correct for meaningful content (like paragraphs), because div is a generic block-level container with no semantic meaning. It is used primarily for grouping and styling.

    Also:

    So, when is text inside div acceptable?

    When text is not meant to be semantically meaningful (like placeholder text or layout text).

    For a clear examples, consider using div for:

    Even then, its better to use HTML5 semantic tags if possible.