+ 6
What is the difference between <div> and <span>?
6 ответов
+ 17
Div is a block-element, used like a container.
Span is a inline-element, used for inline text.
--------------------------------
<div>
<h2> Lorem Ispum </h2>
<span> Lorem Ipsum la la la </span>
</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~
<span> Lorem Ipsum la la la </span>
--------------------------------
+ 9
Adding to @Maz, <span> tag is meant for applying inline styles to the content that is otherwise not possible.
<span style="color:red:font-weight:bold">Important Text</span>
+ 6
span is inline element
div is a block element
+ 6
Try running a code using div and span. You will get the difference by seeing the output.
+ 3
<div> for container (block)
<span> for texts (inline)
But <div> is an older element of HTML.
In HTML5, there is already:
<main>
<article>
<section>
<header>
<nav>
and many more which is more readable and easy to understand than <div>.