Sonzaschool
Back

O-Level · Form 2 · Vocational · Electronics and Computer

Computer Programming

Implementing the box model in CSS

about 3 minutes to read

Discussions
Topics in this sectionFormatting web pages with Cascading Style Sheets (CSS)5 topics

The CSS box model describes how every HTML element is rendered as a rectangular box, made up of four layers: content, padding, border, and margin. Understanding how these layers work together helps you control the spacing, size, and appearance of elements on a web page.

1. Content

The content area is where your text, images, or other inner elements appear. You control its size using the width and height properties.

div {
  width: 200px;
  height: 150px;
}

2. Padding

Padding creates space inside the border, between the content and the border edge. It pushes the content away from the box edges.

div {
  padding: 20px;
}

You can also set padding for each side individually:

  • padding-top, padding-right, padding-bottom, padding-left

3. Border

The border surrounds the padding (or content if there is no padding). You can set its width, style, and color.

div {
  border: 3px solid #0066cc;
}

Common border styles include solid, dashed, dotted, and double.

4. Margin

Margin creates space outside the border, separating the box from neighboring elements.

div {
  margin: 15px;
}

Like padding, you can set margins for each side individually: margin-top, margin-right, margin-bottom, margin-left.

How you'll be assessedProcess assessment · Outcome assessment · Knowledge assessment

Process assessment

  • Set width and height of elements.
  • Apply padding, margin, and border.
  • Test and adjust spacing between elements.
  • Use box sizing property.
  • Preview and verify box model implementation.

Outcome assessment

Web pages with a box model employing CSS are implemented correctly.

Knowledge assessment

Methods used: The student should explain how to:

  • implement the CSS box model.

Principles: The student should explain the principle of:

  • spacing and boxsizing.

Theories: The student should explain:

  • CSS box model structure

Circumstantial knowledge:

Detailed knowledge about:

  • border styles and effects.

Question

Which of the following lists the four layers of the CSS box model in the correct order, from innermost to outermost?

Sign in to submit your answer and have it count toward your mastery.

Sign in to practice

Tutor

Stuck? Ask me anything about this topic.

Sign in to ask the Sonza AI Tutor about this question.

Sign in to ask

Discussions

No questions yet

Sign in to ask
Loading discussions…