CSS margin-left Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The margin-left property sets the margin area on the left of an element. A positive value moves the box farther from neighbors on the left; a negative value pulls it closer.

It is part of the box model (outside the border), is not inherited, and always targets the physical left edge. Prefer margin-inline-start when spacing should follow text direction (LTR/RTL).

Baseline · Widely available.

Not deprecated. Core length, percentage, and auto values work across modern browsers.

CSS Syntax

syntax.css
margin-left: <length> | <percentage> | auto | inherit;

Example: margin-left: 1.5rem;. Values may be positive, zero, or negative.

Property Values

ValueDescriptionTry it
<length>Fixed size such as 16px or 1emTry it
<percentage>Relative to the containing block’s width (inline size)Try it
autoAbsorbs leftover horizontal space (often used to push or center)Try it
Negative lengthPulls the element toward content on its leftTry it
0 / initialNo left margin (initial value is 0)Try it
inheritTakes the parent’s margin-leftTry it

How to Use margin-left

Use it to indent a box or create space on its physical left side.

  1. Select the element that needs space on the left.
  2. Set a length (1rem, 24px) or a percentage of the container width.
  3. Use auto when you want leftover space absorbed on the left (for example to push a fixed-width block right).
  4. For RTL-friendly layouts, prefer margin-inline-start instead.
PieceRequired?Role
Any element (typical)YesApplies broadly; table internals use border-spacing instead
Length, %, or autoYesSets the left outer space
InheritedNoSet on each element that needs it
Defined width (for auto)OftenCentering / push-right with auto needs free horizontal space

Live Preview

Change margin-left on the yellow box and watch the gap before it.

Percentages are based on the container width. The left edge stays physical even in RTL.

Inline row
Prev Target

margin-left: 24px

CSS Examples

Each snippet focuses on margin-left. Use Try It Yourself for a live editor.

Example 1 — Length Indent

Add a fixed gap on the left of a box.

CSS
<style>
  .card {
    margin-left: 24px;
  }
</style>

<span>Prev</span>
<span class="card">Card</span>
Try It Yourself

How It Works

  1. Target the second box. The rule applies to .card.
  2. Set 24px. Outer space appears on the physical left.
  3. Prev stays on the left of that gap.
  4. Not padding. The space is outside the border.

Example 2 — Percentage

Size the left margin from the container width.

CSS
<style>
  .box {
    margin-left: 10%;
  }
</style>

<div class="box">Box</div>
Try It Yourself

How It Works

  1. Percent of width. The margin is a fraction of the containing block’s inline size.
  2. Wider parent → larger indent. The left margin scales with container width.
  3. Useful for responsive indents without fixed pixels.
  4. Try resizing the editor pane to see the gap change.

Example 3 — Auto (Push Right)

Let leftover space go to the left so the box sits on the right.

CSS
<style>
  .wrap {
    width: 220px;
  }
  .box {
    width: 80px;
    margin-left: auto;
  }
</style>

<div class="wrap">
  <div class="box">Right</div>
</div>
Try It Yourself

How It Works

  1. Give the box a width so free space exists in the parent.
  2. Set margin-left: auto. Unused space goes to the left.
  3. The box moves right inside the container.
  4. Both sides auto (margin-left and margin-right) centers the box instead.

Edge Cases & Pitfalls

If the left gap looks wrong or missing, check these first.

physical

Always the physical left

In RTL, margin-left still means left — not the start of the text. Use margin-inline-start for direction-aware spacing.

overconstrained

Width + both margins can ignore left

MDN: when width, padding, border, and both horizontal margins are all fixed, margin-left may be treated as if it were auto.

percent

% is based on width

Percentage margins resolve against the containing block’s inline size (width in horizontal writing modes).

vs

margin-left vs padding-left

Use padding-left for inner space (backgrounds extend into padding). Use margin for space between separate boxes.

collapse

Horizontal margins do not collapse

Unlike top/bottom, left and right margins between siblings do not merge into one gap.

Browser Support

margin-left is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

margin-left

Length, percentage, and auto values work in all modern browsers and older engines.

99% Browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Opera All modern versions
Full support
Samsung Internet Supported
Full support
Internet Explorer Supported
Full support
margin-left Widely supported

Bottom line: Safe for everyday left spacing. Remember RTL vs logical properties. It is not a runtime API.

Key Takeaways

  • Role: outer space on an element’s physical left edge.
  • Initial: 0. Not inherited.
  • Percentages use containing-block width.
  • auto can push right or help center with margin-right: auto.

One line: margin-left adds outer space on the left — outside the border, before the content edge.

Frequently Asked Questions

It sets the outer space on the left of an element, outside its border. A positive value pushes the element away from content on its left; a negative value pulls it closer.
The initial value is 0. There is no left margin until you set one.
margin-left is outside the border, between elements. padding-left is inside the border, between the border and the content.
margin-left always targets the physical left edge. margin-inline-start follows writing mode and direction, so it maps to the right in RTL.
It absorbs leftover horizontal space. Alone on a block it can push the box to the right; with margin-right: auto it centers a block that has a defined width.
It is Baseline Widely available. It is a browser CSS box-model property, not a Node.js runtime feature.

Next: margin-right

Set outer space on the physical right edge.

margin-right tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful