1. Home
  2. Computing & Technology
  3. Web Design / HTML

margin

By , About.com Guide

margin Description:

The margin property is a shorthand tag to define all the margins of an element.

margin in CSS Versions:
margin Syntax:

margin: [ <length> | <percentage> | auto ]{1,4}
margin: <margin-top> <margin-right> <margin-bottom> <margin-left>

  • length
    A specific length (include unit of measure).
  • percentage
    A percentage of the height of the closest block-level ancestor.
  • auto
    Allows the user-agent to define the margin based on inheritance and pre-set user-agent rules.
margin Initial Value:

Not defined

margin Applies To:

All elements.

margin Inheritance:

This property is not inherited.

margin Browser Support:
margin Examples:

set all margins

<p style="margin : 2em;">
This paragraph has a 2 em margin on all sides.
</p>

set top and bottom the same and right and left the same

<p style="margin : 2em 1em;">
This paragraph has a 2 em margin on the top and bottom and a 1em margin on the right and left.
</p>
margin Special Notes:
  • Negative values are permitted, but may be affected by implementation limits.
  • If only 3 values are listed, the left margin is assumed to be the same as the right.
More margin Information:

Return to the Style Library

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Books
  6. About Web Design Book
  7. AWD: Chapter 12
  8. CSS Style Property: margin>

©2009 About.com, a part of The New York Times Company.

All rights reserved.