Is it fine to use span elements in div elements?
Asked Answered
N

2

0

I am making a website with personal articles. The body of my articles is a basic div containing paragraphs, but recently I found it useful to use some span's out of the paragraphs to manage my content as desired, hence in the div's.

As the web semantic becomes an important role and becomes more and more well constrained, I was curious of the downsides of such a practice.

I am not too familiar with the standards of HTML yet. However, I was thinking using span's in div's is semantically not clean.

Is the Googlebot going to soil the referencing on that?

Nodus answered 24/4, 2015 at 16:23 Comment(1)
Could you include an example? In my answer I assumed you are using the span elements for some text (e.g., Hello <span>world</span>!), but re-reading your question, I wonder if you intend to use them differently.Inauspicious
T
4

There is nothing wrong with using a span element inside of a div element. It is absolutely valid. It will have no negative impact on search engine optimization.

div elements are block elements and span elements are inline elements. Inline elements can be placed inside of block elements. The opposite is what you want to avoid: Do not put div elements inside span elements.

Tiki answered 24/4, 2015 at 16:25 Comment(0)
I
0

It’s fine if no other text-level element is appropriate in your case.

You can check their purposes in the usage summary: Does it represent a hyperlink, stress emphasis, importance, a side comment, …? If the answer is no to all candidates, go with "Other", i.e., the span element.

div and span elements don’t represent anything, they are meaningless elements to be used in cases where no other element is appropriate. So adding/removing div/span elements would never change the semantics of the document (unless meaningful attributes, like lang, were used).

Inauspicious answered 25/4, 2015 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.