-
Hajipur, Bihar, 844101
<div>
in HTML?The <div>
tag in HTML stands for "division" and is used as a container element to group and style HTML elements using CSS or JavaScript.
It is a block-level element, meaning it starts on a new line and stretches the full width of its parent.
<div>
<!-- Content goes here -->
</div>
<div>
Grouping elements logically
Styling sections with CSS
Applying JavaScript interactions
Building layouts (like header, sidebar, footer)
<div>
<h2>News</h2>
<p>Latest updates go here.</p>
</div>
You can assign a class or ID to a <div>
for styling and targeting.
<div class="container">
<h1>Welcome</h1>
</div>
<div id="footer">
<p>Copyright © 2025</p>
</div>
<div>
with CSS<style>
.box {
background-color: #f2f2f2;
padding: 20px;
border: 1px solid #ddd;
}
</style>
<div class="box">
<p>This is a styled div.</p>
</div>
<div>
Tags<div class="outer">
<div class="inner">
<p>Nested content</p>
</div>
</div>
<div>
<div class="header">Header</div>
<div class="menu">Menu</div>
<div class="content">Main Content</div>
<div class="footer">Footer</div>
Q1. Create a <div>
that contains a heading and paragraph.
Q2. Use a <div>
with a class name and apply background color using CSS.
Q3. Group three paragraphs inside one <div>
.
Q4. Create a layout with four <div>
s: header, sidebar, content, and footer.
Q5. Add borders and padding to a <div>
using CSS.
Q6. Create nested <div>
blocks and style them differently.
Q7. Center-align text inside a <div>
using CSS.
Q8. Assign an ID to a <div>
and target it with CSS.
Q9. Use JavaScript to change the content inside a <div>
.
Q10. Display two <div>
s side by side using display: inline-block
.
Q1: What does the <div> tag represent in HTML?
Q2: What is the default display behavior of <div>?
Q3: How can you apply a style to a <div>?
Q4: Which of the following can be grouped inside a <div>?
Q5: What is the purpose of giving a class to a <div>?
Q6: What will happen if you nest <div> elements?
Q7: Which tag is commonly used with <div> to separate layout sections?
Q8: Which CSS property can you use to style the border of a <div>?
Q9: What tag is used for inline text grouping instead of <div>?
Q10: How can you make a <div> float next to another?