CSS margin-left Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Box Model

What You’ll Learn

The margin-left property adds outer space on the left side of an element. It is one of the most common tools for horizontal spacing and alignment in CSS.

01

Left Space

Outside border.

02

Box Model

Outer spacing.

03

Indent

Offset content.

04

Units

px, rem, %.

05

Physical

Always left.

06

Default 0

No spacing.

Introduction

The margin-left property in CSS is used to set the left margin of an element. This property allows you to create space to the left of an element, pushing it away from the elements on its left.

Margins are essential for controlling the layout and spacing of elements on a web page, providing a clean and organized appearance.

Definition and Usage

Apply margin-left when you need spacing on only the left side without changing top, right, or bottom margins. It is ideal for indenting paragraphs, offsetting cards, and creating horizontal gaps between inline or block elements.

💡
Beginner Tip

margin-left creates space outside the border on the left. Use padding-left when you need space inside the border.

📝 Syntax

The syntax for the margin-left property is straightforward. You can specify the value using different units, such as pixels (px), percentages (%), ems (em), and more.

syntax.css
element {
  margin-left: value;
}

Here, value can be a length, percentage, or one of the global values (inherit, initial, unset).

Basic Example

margin-left.css
p {
  margin-left: 30px;
}

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toAll elements except table display types that use separate border model
InheritedNo
AnimatableYes, as a length
Logical equivalentmargin-inline-start (in horizontal LTR writing)

💎 Property Values

ValueExampleMeaning
Lengthmargin-left: 30px;Fixed margin in px, em, rem, etc.
Percentagemargin-left: 10%;Margin as a percentage of the containing element width
automargin-left: auto;Browser calculates the margin; useful in flex and grid layouts
inheritmargin-left: inherit;Inherits the margin-left value from the parent element
initialmargin-left: initial;Sets the property to its default value (0)
unsetmargin-left: unset;Resets to inherit or initial depending on context
margin-left: 1rem; margin-left: 30px; margin-left: 5%;

🎯 Default Value

The default value of the margin-left property is 0, meaning no extra space is added to the left of the element. Override it when you need spacing on the left outer edge.

👀 Live Preview

A box with left margin inside a dashed container:

margin-left: 1.25rem

Examples Gallery

Add left margin to a paragraph, indent nested content, offset a card from the edge, and compare with the logical equivalent.

🔢 Left Spacing

Start with the reference example — add a left margin to a paragraph element.

Example 1 — Paragraph Left Margin

Add a left margin of 30 pixels to a paragraph element.

margin-left.html
<style>
  p {
    margin-left: 30px;
  }
</style>

<p>This paragraph has a left margin of 30 pixels.</p>
Try It Yourself

How It Works

Only the left outer edge gets spacing. The paragraph shifts right, creating a gap from the container edge or preceding content.

Example 2 — Indented List Items

Use left margin to indent nested list items.

margin-left-list.css
ul ul {
  margin-left: 1.5rem;
}
Try It Yourself

How It Works

Left margin pushes nested lists inward, creating a visual hierarchy without changing list markers.

📈 Layout & Logical Properties

Offset content from the left edge and understand the logical property equivalent.

Example 3 — Card Offset from Edge

Push a card away from the left edge of its container.

margin-left-card.css
.card {
  margin-left: 2rem;
  padding: 1rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  max-width: 16rem;
}
Try It Yourself

How It Works

Left margin creates horizontal offset. This is useful for sidebar layouts, timelines, and staggered content blocks.

Example 4 — Physical vs Logical

In horizontal LTR writing, margin-left matches margin-inline-start:

margin-left-logical.css
/* Physical */
.note {
  margin-left: 1.5rem;
}

/* Logical equivalent in horizontal LTR */
.note {
  margin-inline-start: 1.5rem;
}
Try It Yourself

How It Works

For simple English LTR pages, margin-left is familiar and widely used. Choose margin-inline-start when direction may change.

margin-left in the Box Model

Margin sits outside the border. Left margin specifically adds transparent space on the left side of the element:

  • Content — text or child elements inside the box.
  • Padding — inner space between content and border.
  • Border — the visible edge.
  • Margin-left — outer space on the left side of the border.

♿ Accessibility

  • Keep indentation meaningful — Left margin can indent nested content without breaking semantics.
  • Do not rely on empty elements for spacing — Use margin instead of blank divs.
  • Test zoomed layouts — Large left margins can push content off-screen on small viewports.
  • Consider RTL layouts — Use logical properties when direction may change.
  • Combine with semantic HTML — Margins adjust spacing; structure still comes from proper elements.

🧠 How margin-left Works

1

You set left spacing

Apply margin-left with px, rem, %, or a keyword.

CSS rule
2

Browser reserves space

Transparent margin area is added on the left side, outside the border.

Box model
3

Element shifts right

The element moves away from the left, creating horizontal separation.

Layout
=

Aligned spacing

Content is offset or indented with clear left-side separation.

🖥 Browser Compatibility

The margin-left property is widely supported across all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. This means you can use this property confidently, knowing it will render consistently across different platforms and devices.

Universal · All browsers

Core layout spacing everywhere

margin-left is one of the most fundamental CSS properties. You can rely on it in any project.

99% Global browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Legacy & Chromium
Full support
Opera All versions · Modern & legacy
Full support
margin-left property 99% supported

Bottom line: Safe to use everywhere. For direction-aware spacing, see margin-inline-start.

🎉 Conclusion

The margin-left property is a versatile and essential tool in CSS for managing the layout and spacing of elements on your web pages.

Whether you’re looking to align content, create space between elements, or design a unique layout, understanding how to use margin-left effectively can help you achieve your design goals. Experiment with different values and units to see how they impact your design.

💡 Best Practices

✅ Do

  • Use margin-left for indents and horizontal offsets in LTR layouts
  • Prefer rem for scalable left spacing
  • Combine with other margin longhands for precise control
  • Consider margin-inline-start for multilingual pages
  • Use consistent left margins for aligned content blocks

❌ Don’t

  • Confuse margin-left with padding-left
  • Use empty divs only to create spacing
  • Use huge fixed margins that break mobile layouts
  • Rely on physical left margin in RTL layouts without testing
  • Apply left margin when flex or grid gap would be cleaner

Key Takeaways

Knowledge Unlocked

Five things to remember about margin-left

Use these points when spacing elements on the left side.

5
Core concepts
0 02

Default 0

No spacing.

Default
rem 03

Scalable

Use rem.

Units
in 04

Indent

Offset content.

Use case
pad 05

Not padding

Inside vs out.

Box model

❓ Frequently Asked Questions

The margin-left property sets outer spacing on the left side of an element, outside of its border. It pushes the element away from content on its left.
The default value is 0, meaning no extra space is added to the left of the element unless you set one explicitly.
margin-left adds space outside the border between elements. padding-left adds space inside the border between the border and the content.
margin-left always targets the physical left edge. margin-inline-start follows text direction and adapts in RTL layouts.
Yes. margin-left: auto can absorb leftover horizontal space in flex and grid layouts, though margin: 0 auto is more common for centering block elements.

Practice in the Live Editor

Open the HTML editor, try different margin-left values, and see how left spacing changes your layout.

HTML Editor →

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.

5 people found this page helpful