Advertisement

Advertisement


CSS Box Model

It is nothing but a term used to represent an element with it's properties. According to the CSS box model, a browser engine represents every element as a box. The content, padding, margins and borders, all together represents a box that wraps around every html element.

Parts of Box Model

Value Description
Content The content of the box, where text and images appear
Padding Clears an area around the content. The padding is transparent
Border A border that goes around the padding and content
Margin Clears an area outside the border. The margin is transparent

<!DOCTYPE html>
<html lang="en">
<head>
<title> CSS Box Model </title>
<meta charset="UTF-8">
<style>
div {
background-color: #e3fdcb;
width: 300px;
border: 10px solid seagreen;
padding: 25px;
margin: 25px;
}
</style>
</head>
<body>
<h2>Demonstrating the Box Model</h2>
<p>The CSS box model is essentially a box that wraps around every HTML element.
It consists of: borders, padding, margins, and the actual content.</p>
<div>This text is the actual content of the box. We have added a 25px padding,
25px margin and a 25px green border. </div>
</body>
</html>

Output

CSS Box Model
This text is the actual content of the box. We have added a 25px padding, 25px margin and a 25px green border. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.








Become a Patron!

Note: If the updated content is not visible to you please refresh the cookies by pressing CTRL + Shift + R.