CSS Tutorials

Box Model In CSS
Previous Home Next

All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around HTML elements.In CSS, the term box model is used when talking about design and layout of the HTML webpage;

    This consists of three types:

  1. Margin: Clears an area outside the border.The margin represents the distance between the outer edge of the border and any neighboring elements. This is often a source of confusion as it’s easy to think of the margin as a kind of “padding” between elements. Better to think of it like the margin of a page, it represents the outer edge of the object.

  2. Syntax:

    margin: <margin-top>
  3. Padding: Padding specifies the spacing between the border and any content within the HTML element. If there’s no visible border, then the extent of the padding is effectively the extent of the element. Any background CSS properties associated with the element are displayed within the area defined by the border and padding properties.

  4. Syntax:

    padding: <padding-top>
  5. Border: The border represents the effective outer limit of the element itself. The border can be either visible or invisible, and has properties for line type, color, and width.A border that goes around the padding and content.

  6. Content: The content of the box, where text and images appear.


Simple Example
<TITLE>Examples of margins, padding, and borders</TITLE>
<STYLE type="text/css">
UL { 
margin: 12px 12px 12px 12px;
padding: 5px 5px 5px 5px;
LI {  
margin: 12px 12px 12px 12px ;
padding: 12px 0px 12px 12px;
font:Arial, Helvetica, sans-serif; 
LI.withborder {
border-width: medium;
<LI class="withborder">Element of list is
 a bit longer to illustrate wrapping.</LI>


Previous Home Next