w3schools    w3Schools
Search W3Schools :
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

XML Certification
Download XML editor
Custom Programming
Table of contents
CSS Basic
CSS Introduction
CSS Syntax
CSS How To
CSS Background
CSS Text
CSS Font
CSS Border
CSS Outline
CSS Margin
CSS Padding
CSS List
CSS Table

CSS Advanced
CSS Dimension
CSS Classification
CSS Positioning
CSS Pseudo-class
CSS Pseudo-element
CSS Image Gallery
CSS Image Opacity
CSS Media Types
CSS Don't
CSS Summary

CSS Examples
CSS Examples

CSS2 Reference
CSS2 Print
CSS2 Aural
CSS Units
CSS Colors
CSS Colorvalues
CSS Colornames

CSS Quiz
CSS Quiz
CSS Exam

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Tutorials
W3Schools Forum

Helping W3Schools


CSS margin Property

CSS Reference Complete CSS Reference


The margin property is a shorthand property for setting all of the properties for the four margins in one declaration.

Note: Negative values are allowed.

Inherited: No

JavaScript Syntax

CSS properties can also be dynamically changed with a JavaScript.

Scripting Syntax: object.style.margin="100px"

In our HTML DOM tutorial you can find more details about the margin property.

In our HTML DOM tutorial you can also find a full Style Object Reference.


h1 {margin: 10px}
all four margins will be 10px

h1 {margin: 10px 2%}
top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.

h1 {margin: 10px 2% -10px}
top margin will be 10px, left and right margin will be 2% of the total width of the document, bottom margin will be -10px

h1 {margin: 10px 2% -10px auto}
top margin will be 10px, right margin will be 2% of the total width of the document, bottom margin  will be -10px, left margin will be set by the browser

Possible Values

Value Description
Sets the properties for the margins. The values comes in % (defines a margin in % of the total height/width of the document), length (defines a fixed margin), and auto (the browser sets a margin).

Default value: Not defined

Try-It-Yourself Demos

All the margin properties in one declaration
This example demonstrates how to set a shorthand property for setting all of the margin properties in one declaration.

CSS Reference Complete CSS Reference

Altova® MissionKit® - Integrated suite of XML tools

The Altova MissionKit is a suite of intelligent XML tools, including:

XMLSpy® – industry-leading XML editor

  • Support for all XML-based technologies
  • Graphical editing views, powerful debuggers, code generation, & more

MapForce® – graphical data mapping tool

  • Drag-and-drop data conversion with code generation
  • Support for XML, DBs, EDI, Excel® 2007, text, Web services

StyleVision® – visual stylesheet designer

  • Drag-and-drop stylesheet design for XML & databases
  • Output to HTML, PDF, RTF, Word 2007, & more

And more…

Try before you buy with a free fully functional 30-day trial

Download today

ASP.NET Web Hosting
Web Hosting
$15 Domain Name
Save $20 / year!
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
Home HOME or Top of Page Validate   Validate   W3C-WAI level A conformance icon Printer Friendly  Printer Friendly

W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user.
While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright 1999-2009 by Refsnes Data. All Rights Reserved.