Grouping Elements - Notes
Grouping Elements - Notes
Topics Covered:
● What is the <div> tag and its purpose in HTML?
● What is the <span> tag and its purpose in HTML?
● How is the <div> different from <span>?
Topics in Detail:
<div> tag:
● <div> tag in HTML defines the division/section in the document.
● <div> tag is the container of HTML elements.
● It is easy to apply styles and scripts to the HTML elements when they are inside the
<div> tag with help of the attributes of the <div> tag.
● The class and id attributes help in styling and applying scripts to the HTML elements
inside the <div> </div>.
● <div> is a block-level element, so there will be a line before and after the <div> </div>.
● <div> is the most important tag in web development, because it helps us to separate the
content/data in the web page, and helps us to apply different styles and behaviors to
different divisions.
● <div> tag is used to group the large section of HTML elements together.
● <div> tag encapsulates HTML elements and divides the HTML document into sections.
● <div> tag cannot be used inside <p> element.
● Example:
1
Few sub divisions inside the <div class= “header”> </div>
2
<span> tag:
● <span> tag is an inline container.
● <span> tag is used to markup part of text/ content in an element.
● <span> tag also helps to apply styles and scripts easily with help of id and class
attributes similar to <div> tag, but <div> is a block-level element and <span> is an inline
element.
● <span> can be used inside <p> tags, to apply different styles to part of the content in the
<p> tag.
● Example:
span tags used inside the div tags in the web page
3
Difference between div and span tags:
<div> <span>
The <div> tag is a block level element. The <span> tag is an inline element.
This tag should be used to wrap a section, for This tag should be used to wrap any specific
highlighting that section. word that you want to highlight in your
webpage.
<div> tag displayed in a new line. <span> tag does not begin a new line.