Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Borders, margins and padding

CSS also allows you to manage the space around a tag. This is what the W3C call the box model. Each tag has a content area (text, a picture and so on) and optional surrounding padding, border and margin areas.

The following diagram shows how the areas relate:

One thing: padding is inside a tag and the margin is outside it. This means that margins do not take on the tag’s background (for example a colour) but the padding does. If a paragraph has a white background and your page background is blue, the margins will be blue but the padding will be white.

You should also note that if you apply a margin to the <body> tag, it affects all the tags inside the body. If you set a left margin of 1", all your tags will have an initial margin of 1".