CSS-Box-Model

Home / CSS / CSS-Box-Model

CSS-Box-Model


CSS-Box-Model:

The CSS Box Model is a fundamental concept in web design and layout that defines how HTML elements are rendered as boxes on a web page. It consists of four main components: content, padding, border, and margin. These components determine the size and spacing of elements on a webpage.

Content: This is the innermost part of the box and contains the actual content, such as text, images, or other HTML elements. The content area's dimensions can be specified using properties like width and height.

Padding: The padding is the space between the content and the border of the box. It provides inner spacing within the element. You can set the padding using properties like padding-top, padding-right, padding-bottom, and padding-left, or shorthand properties like padding.

Border: The border surrounds the padding and content and is typically a line or series of lines that form the outer boundary of the box. You can control the border's width, style, and color using properties like border-width, border-style, and border-color. Like padding, you can use shorthand properties like border to set all border properties at once.

Margin: The margin is the space outside the border, which separates the element from other elements on the webpage. It creates spacing between elements. You can specify margins using properties like margin-top, margin-right, margin-bottom, and margin-left, or shorthand properties like margin.

Example: 
 
<style>
    .box{
      height: 200px;
      width: 200px;
     
    }
    .box1{
      height: 100px;
      width: 100px;
    }
   
  </style>
</head>
<body>
  <div class="box">
  <div class="box1"></div>  
</div>
</body>

Output: