Skip to main content
D
CSS
CSS Margins

CSS Margins

CSS margins create empty space completely outside an element.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

CSS creates transparent space around the outside of an element's border. Developers use margins to push elements apart from each other on the page. You can set the margin for all four sides independently.

Example

Example
1/* this sets margins */
2div {
3  margin-top: 50px;
4  margin-bottom: 20px;
5  margin-right: 10px;
6  margin-left: 10px;
7}

Key Points

  • Margins sit outside the element's border.
  • The space is completely transparent.
  • Margins push neighboring elements away.
  • The `margin` shorthand sets all four sides at once.

Up Next

Continue your journey with the next topic.

Go to CSS Padding