Jitendra Vyas Jitendra Vyas - 3 months ago 13
CSS Question

How do you choose when to use DIV and when SPAN, to wrap something?

How do you choose when to use

DIV
and when
SPAN
, to wrap something?

Many time when we make PSD 2 HTML, in some conditions to get any effect or to wrap something to get needed effect, we use
div
or
span
.

And I know
div
is block level element and
span
is inline level element and we can change display properties through CSS. and I also know
div
cannot come inside
span
.

What are cases when you use
div
as a
display:inline
and
span
as a
display:block
? and should we try to avoid those scenarios? is this semantically incorrect?

and when we use blank
div
or
span
(no content inside) to get some effect, than which is correct?

Answer

As you note, you should use divs as dividers of blocks, and spans for marking inline content.

And yes, you should try to avoid changing the display types of them.