box model css | box model in css

box model css | box model in css 


Box Model is a box that contains multiple CSS properties like borders, padding, margin, and HTML content itself.

It is used to create the structure and design of web pages. It can be used as a set of tools to personalize the structure of different components.

In the CSS box model, the web browser supplies each element as a rectangular box.

Box model has four important properties in CSS :

  • margin
  • border
  • padding
  • content

box model css | box model in css

Margin Area: Area outside the border. The margin area is invisible. The dimensions of the margin area are the margin-box height and margin-box width. 

Border Area: Area between the box padding and margin. You can see it in the figure. Its dimensions are given by the height and width of border.

Padding Area: It is the Area between the content box and border-box. It includes the element’s padding. Its dimensions are given by the width of the padding box and the height of the padding box.

Content Area: Area consists of content like image, text, or other media content. Its dimensions are given by content-box width and height.

Javascript project ideas with complete source code 

The size of the box itself is calculated like this:

Total Width = width + padding-left + padding-right + border-left + border-right.

Total Height = height + padding-top + padding-bottom + border-top + border-bottom.



<!DOCTYPE html>




div {

  width: 420px;

  padding: 10px;

  border: 5px solid gray;

  margin: 0;





<h2>Calculate the total width:</h2>

<img src=”” width=”450″ height=”263″ alt=””>

<div>The picture above is 450px wide. The total width of this element is also 450px.</div>





Leave a Reply