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.

  

 

 

 

back to top