CSS Box Model: 5 Steps To Turn an Element into a Box

Box your HTML elements up like a guru

Yang Zhou
TechToFreedom

--

The box model, which is mentioned frequently in front-end developers’ interviews, is an important concept of CSS. After all, to design the layout of a page is to manage the boxes on it.

A box is a concept. There is no original HTML tag named <box>.

It’s combined with 4 parts: content, padding, border and margin. The HTML element in a box is the content. We can control these parts precisely by CSS to decorate and manipulate the element.

The structure of a CSS box
Photo from W3School

The above photo shows the basic structure of a box. This article will provide a step-to-step guide about how to put these parts together and turn a plain element into a box. After reading, you can box your HTML elements up like a guru. 👍

1. Define an Element as the Content of a Box

First of all, let’s define a simple element as the content:

<p class="content">Weekly Hottest Articles by Yang Zhou:<br>3 Uses of the Three Dots in JavaScript<br>

--

--