margin CSS property is used to set the outer spacing or margins of an element. It controls the space between an element’s border and adjacent elements or the containing element.
margin property can accept one to four values, representing the top, right, bottom, and left margins, respectively. Each value can be specified using different length units (such as pixels or percentages) or the
Here’s an example:
In this example, the
.box class sets a margin of
10px on all sides of the element. This creates equal spacing between the element and its neighboring elements.
You can also specify different margins for each side individually:
In this case, the
.box class sets a
20px top margin,
10px right margin,
30px bottom margin, and
15px left margin.
margin property is commonly used to control the spacing around elements, creating gaps or separating elements within a layout. It helps achieve desired visual spacing and alignment in CSS designs.