Div vs. Span
The <div>
element and <span>
element are frequently used elements. These elements don't have any semantics (i.e., these tags don't have any meaning of their own). The <div>
element is a block element by default while the <span>
element is an inline element.
<div>
The <div>
tag is used to group some elements (both block and inline elements) mainly for styling purposes. By grouping elements, you can customize the design of a web page. As it forms a block element, you can also use it to create shapes (boxes) or lines on a web page using background and borderline properties, which will be explained later in this course.
<span>
The <span>
tag is used to group some parts of the text to style the selected part. For example, if you want to change the color of some words in a paragraph, you can use this tag to add a color property. As it is an inline element, you cannot nest block elements in it.