Difference Between Div and Span
Both the general HTML elements span and div serve to group together relevant elements of a web page for various purposes. Although there are a few similarities between the div tag and span tag, there exist a few differences between the div and span tag in HTML. The important differences between the two tags are shown in the table provided below.
|Div vs Span|
|This element of the tag is a block level.||This element or tag is the in-line element.|
|These are used to create small divisions.||Used in between lines and doesn't create a separate section or division.|
|Align attribute is accepted by this tag.||Does not accept align attribute.|
|They are used to highlight a section in the content.||They are used to wrap a word or bunch of words and not the whole section.|
What is Div?
The <div> tag is also known as the division element. It is a generic block-level element. These are the elements that start from a new line. They are widely used to divide the content on the page into different blocks.
A basic example of a <div> tag is shown below.
<td><a href="https://byjusexamprep.com/civil-engineering-exams/gate-civil-exam-analysis" target="_blank" rel="nofollow noopener noreferrer">GATE Civil Review</a></td>
What is Span?
A span tag or element is also known as an in-line element. This is used in the small sections of the content on the page. They do not start a new line. They are used on texts, images, etc which will be present in the line.
A basic example of a <span> tag is shown below.
<p><span style="font-weight: 400;">Civil engineering includes the planning, construction, designing and maintenance of roads, bridges, dams, canals, and buildings.</span></p>
Key Differences Between Div and Span
The key differences between div and span tags in HTML are given below.
- A div is a block-level element, and a span is an inline element.
- Div tag works best if you affix it to a specific area of a website whereas a span tag is preferable to add CSS to a brief line break on a web page.
- Div tag accepts the attribute align while span tag rejects the attribute align.
Commentswrite a comment