What is the difference between DIV and SPAN in HTML?

Submitted 3 years, 2 months ago
Ticket #348
Views 265
Language/Framework Html
Priority Low
Status Closed

Explain?

Submitted on Feb 10, 21
add a comment

2 Answers

Verified

Div is a block-level-element & 
Span is an inline-element.

----------------------------------
Example:
<div> Html </div>
<div> and </div>
<span> Css </span>
<span> Javascript </span>
----------------------------------------
Output for the above example will be as shown
Html
and
CssJavascript
-------------------------------------------------------

As you can see

'div' elements 'Html', 'and' are displayed in a separate line..this is because 'div' is a block level element and it takes up the enire row for each 'div' element whereas 'span' takes up only the space required for the word that is why 'Css','Javascript' are displayed on the same line 

Submitted 3 years, 2 months ago


Verified

The main difference between <div> and <span> is their default behavior. By default <div> is a block level element and <span> is a inline element.

Without breaking the current line element, just to add a small portion of text we will use <span>.

If you need to modify a large division, the height, move an element, or contain other elements, we will use a <div>.

Submitted 3 years, 2 months ago


Latest Blogs