CSS Box Model: Width and Height of an Element

div {
  width: 320px;
  padding: 10px;
  border: 5px solid gray;
  margin: 0; 
}

//The total width of an element should be calculated like this:

// 320px (width)
// + 20px (left + right padding)
// + 10px (left + right border)
// + 0px (left + right margin)
// = 350px


// Total element height = height + top padding + bottom padding + top border 
//+ bottom border + top margin + bottom margin

When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add padding, borders and margins.

Related concepts

Width and Height of an Element

CSS Box Model: Width and Height of an Element — Structure map

Clickable & Draggable!

CSS Box Model: Width and Height of an Element — Related pages: