XML technologies / CSS / CSS Cookbook / Typography for the web / Removing space between headings and paragraphs
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to reduce the space between a heading and a paragraph.
Solution
Set the values of margin and padding to zero for the heading and paragraph:
h2 {
margin: 0;
padding: 0;
}
p {
margin: 0;
padding: 0;
}Discussion
Browsers use an internal stylesheet to define default values for HTML elements. This includes padding and margins for headings and paragraphs.
These defaults make documents without styles easier to read. Many web developers, however, prefer their own settings.
To remove the default spacing between headings and paragraphs, set the values of margin and padding to zero for the elements h2 (or other headings such as h1, h3 etc.) and p.
See also
The default stylesheet for HTML 4 in the CSS 2.1 specification.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln