What is the difference between div and span?
HTML web pages contain many elements and tags. Both div and span tags represent a part of any webpage.
div tag
The div tag is mainly used to divide up content on the web page. Since the div tag is a block element, the entire width of the block is assigned to the div element.
If you apply a
divto a text paragraph, the entire block of the page will become part of thediv.
span tag
The span tag is referred to as a generic inline container – it can target a specific text in a paragraph and apply styling attributes. This is done through the class or id attributes of the span.
Code
As you can see, the text with the ‘black’ background is part of the div – it contains the entire width of the page. However, the part of the sentence “Welcome to educative”, with the yellow background, is part of a span. We can use span to apply styling to only this sentence rather than the entire content.
Free Resources