Div and Span: HTML Class Notes

Updated: Aug 17

Mobiprep has created last-minute notes for all topics of HTML to help you with the revision of concepts for your university examinations. So let’s get started with the lecture notes on HTML.

  1. HTML Introduction

  2. HTML Tags and Elements

  3. Attributes and Hyperlinks

  4. Headings and Lists

  5. Class and id attributes

  6. Semantic Elements

  7. Inline and Block-Level Elements

  8. Div and Span

  9. Img

  10. Tables

  11. Forms

Our team has curated a list of the most important questions asked in universities such as DU, DTU, VIT, SRM, IP, Pune University, Manipal University, and many more. The questions are created from the previous year's question papers of colleges and universities.

  1. What is the function of <div> element in HTML?

  2. What are the attributes that can be used with div element?

  3. Explain <span> element in HTML.

Div and Span


Question- 1) What is the function of <div> element in HTML?

Answer: This is the very important block level tag which plays a big role in grouping various other HTML tags and applying CSS on group of elements. It acts as a container for other elements.


 

Question- 2) What are the attributes that can be used with div element?

Answer: Although <div> element doesn’t require attributes but there are three common attributes that can be used-

  1. Style

  2. Class

  3. ID

Example-

<!DOCTYPE html>
<html>
<head> <title>HTML div Tag</title> </head>
<body>
<div style = "color: green">
<h1>This is first group</h1>
<p>Following is a list of sports </p>
<ul>
<li>Cricket</li>
<li>Football</li>
<li>Tennis</li>
<li>Boxing</li>
</ul>
</div>
</body>
</html>

Output:

This is first group Following is list of sports-

● Cricket

● Football

● Tennis

● Boxing


 

Question- 3) Explain <span> element in HTML.

Answer: The span element is used as a container for text. Like <div>, it does not require attributes. Style, class and id are the commonly used attributes.


The <span> element is used to style a certain text within a larger text element.


Example-

<!DOCTYPE html>
<html>
<head>
<title>HTML span Tag</title>
</head>
<body>
<p>This is my <span style = "color:red">first assignment</span>.I am <span style = "color:purple">learning </span></p> a lot from it.
</body>
</html>

Output:

This is my first assignment. I am learning a lot from it.


 



3 views0 comments

Recent Posts

See All