CSS Portal

CSS margin-left Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The margin-left property defines the space outside an element’s left border, effectively pushing neighboring content away and creating horizontal separation. It is part of the element’s external spacing and contributes to the total space the element occupies in normal flow. While it does not change an element’s border or padding, adjusting this left margin alters how the element and surrounding siblings are positioned relative to each other.

As one side of the box-model margins, margin-left interacts with the other margins and with the shorthand margin, which can set all four sides in a single declaration. Because margins are applied outside the border, increasing the left margin can reduce available inline space and, depending on layout constraints, may push content to a new line or create overflow, especially if the element’s own sizing limits are already close to the container width.

The effect of margin-left also depends on how the element participates in layout: elements with different display behaviors or elements that are floated via float will react differently to left margins. For example, inline-level boxes accept horizontal margins but do not create block-level reflows the same way block boxes do, while floating elements’ placement is influenced by margins when the browser determines the float’s exact position.

When an element is taken out of normal flow by using different positioning modes (see position), left-side spacing is resolved in combination with offset rules and the layout context, so a left margin can add to or subtract from the visual offset produced by positioning. Similarly, because margins affect available space, they work together with an element’s intrinsic or declared size (for example, its width) when determining whether content fits or causes wrapping and scrolling. In practice, margin-left is a primary tool for fine-tuning horizontal spacing, alignment and visual rhythm in a layout.

Definition

Initial value
0
Applies to
All elements
Inherited
No
Computed value
As specified, but with relative lengths converted into absolute pixel values.
Animatable
Yes
JavaScript syntax
object.style.marginLeft

Interactive Demo

Margin Left Example

Syntax

margin-left: <length> | <percentage> | auto

Values

  • <length>Specifies a fixed length, using any standard CSS length units. Negative Values are allowed.
  • <percentage>A percentage always relative to the width of the containing block.
  • inherit

Example

<div class="example">
<h2>margin-left example</h2>
<div class="box">Normal box</div>
<div class="box shifted">Box with margin-left: 40px</div>
</div>
.example {
    font-family: Arial, sans-serif;
    max-width: 600px;
    margin: 24px;
}

.box {
    background-color: #f0f4ff;
    border: 1px solid #8fb0ff;
    padding: 12px 16px;
    width: 200px;
    margin-bottom: 12px;
}

.box.shifted {
    margin-left: 40px;
}

Browser Support

The following information will show you the current browser support for the CSS margin-left property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!