-
Hajipur, Bihar, 844101
Every HTML element can be considered as a box in CSS. The CSS Box Model describes how these boxes are rendered and how space is added around elements.
The box model consists of the following areas:
Content – The actual text or image inside the element
Padding – Space between the content and the border
Border – The outline surrounding the padding
Margin – Space outside the border, between this and other elements
| Margin |
| --------- |
| Border |
| --------- |
| Padding |
| --------- |
| Content |
div {
width: 200px;
padding: 10px;
border: 5px solid black;
margin: 20px;
}
Width applies only to the content.
Padding, border, and margin expand the element’s total space.
Total width = content width + left/right padding + left/right border + left/right margin
Total height = content height + top/bottom padding + top/bottom border + top/bottom margin
To include padding and border in the width/height of the element:
* {
box-sizing: border-box;
}
✅ This prevents layout issues and keeps the box size predictable.
Q1. Create a <div>
with 300px width and 20px padding.
Q2. Add a 5px solid red border around all paragraphs.
Q3. Set a 15px margin around a container div.
Q4. Write CSS to apply 10px padding and 5px margin to all headings.
Q5. Use the box-sizing
property to include padding and border in the element’s width.
Q6. Write a rule that sets a 2px dotted green border for an image.
Q7. Apply 25px top and bottom margin and 10px left and right padding to a section.
Q8. Set different border styles for each side of a box (top, right, bottom, left).
Q9. Create a CSS class .box
that has 10px padding, 3px border, and 15px margin.
Q10. Apply border-box sizing to all elements using the universal selector.
Q1: What does the box model in CSS describe?
Q2: Which is the correct order from inside to outside in the box model?
Q3: What is included in the box-sizing: border-box; model?
Q4: Which property adds space inside an element, between content and border?
Q5: What adds space outside the element’s border?
Q6: What property sets the visible edge of an element?
Q7: Which CSS property affects the space around elements but not the content?
Q8: What happens if box-sizing: border-box; is not used?
Q9: How do you apply the box model rule to all elements?
Q10: Which part of the box model does border: 1px solid black; affect?