Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

CSS margin

Also see the full, alphabetical list of CSS properties


The CSS margin property is shorthand for specifying margin width on all sides of an element. It is classed as "shorthand" because it sets the margin-top, margin-right, margin-bottom and margin-left properties all in one place.

Syntax: margin: <value1> <value2> ...;
Possible Values:
  • <margin-width> (specify one for each side, or 1 for all)
  • inherit
Initial Value: not defined
Applies to: All elements
Inherited: No
Media: Visual
Example:
margin:10px;
  • All four sides have a margin of 10 pixels.
margin:10px 20px;
  • Top and bottom have a margin of 10 pixels.
  • Right and left have a margin of 20 pixels.
margin:10px 20px 30px;
  • Top is 10px
  • Left and right are 20px
  • Bottom is 30px
margin:10px 20px 30px 40px;
  • Top is 10px
  • Right is 20px
  • Bottom is 30px
  • Left is 40px
Try it yourself!


Also see all CSS properties listed alphabetically


Enjoy this website?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com