Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Adding Space to Elements | Box Model and Element Spacing

Adding Space to ElementsAdding Space to Elements

The margin, padding, and border properties help us add more space to elements, improving the web resource's appearance, readability, and usability. Let's take a closer look at each of them.

padding property

padding refers to the space between an element's content and its border.

“padding”

We have multiple ways to give a value to padding.

Shorthand

Each Padding Separately

margin property

margin refers to the space between an element and the adjacent elements. It is the area outside the element's border.

margin

We can give margin in a couple of ways.

Shorthand

Each Margin Separately

border property

border refers to the line that surrounds an element's padding and content. It is the area that separates the element's content from its margin.

border

Shorthand

It means that the border of all sides will look the same. Their width is 4px, style is solid, and color is brown.

Let's consider the following example and figure out the possible border styles:

html

index.html

css

index.css

js

index.js

Each Border Separately.

1. What is the difference between `margin` and `padding` in CSS?
2. What is the purpose of the `border` property?
3. How can we apply different `margin` values to different sides of an element?

What is the difference between margin and padding in CSS?

Selecciona la respuesta correcta

What is the purpose of the border property?

Selecciona la respuesta correcta

question-icon

How can we apply different margin values to different sides of an element?

Selecciona unas respuestas correctas

¿Todo estuvo claro?

Sección 3. Capítulo 3

Adding Space to ElementsAdding Space to Elements

The margin, padding, and border properties help us add more space to elements, improving the web resource's appearance, readability, and usability. Let's take a closer look at each of them.

padding property

padding refers to the space between an element's content and its border.

“padding”

We have multiple ways to give a value to padding.

Shorthand

Each Padding Separately

margin property

margin refers to the space between an element and the adjacent elements. It is the area outside the element's border.

margin

We can give margin in a couple of ways.

Shorthand

Each Margin Separately

border property

border refers to the line that surrounds an element's padding and content. It is the area that separates the element's content from its margin.

border

Shorthand

It means that the border of all sides will look the same. Their width is 4px, style is solid, and color is brown.

Let's consider the following example and figure out the possible border styles:

html

index.html

css

index.css

js

index.js

Each Border Separately.

1. What is the difference between `margin` and `padding` in CSS?
2. What is the purpose of the `border` property?
3. How can we apply different `margin` values to different sides of an element?

What is the difference between margin and padding in CSS?

Selecciona la respuesta correcta

What is the purpose of the border property?

Selecciona la respuesta correcta

question-icon

How can we apply different margin values to different sides of an element?

Selecciona unas respuestas correctas

¿Todo estuvo claro?

Sección 3. Capítulo 3
some-alt