Do HTML Headings (<h1> - <h6>) have a default padding in any browser?

Viewed 829

Someone asked my friend how to remove the space around a heading tag, and he answered with

h1 {
  margin: 0;
  padding: 0;
}

But I've never actually seen padding around a heading. Only margin, in every browser I got. So now I'm wondering, is there actually any browser, in which there is padding around the headings by default?

Or is it a standard that all browsers follow, to not put padding around headings? Is the padding: 0; unnecessary?

1 Answers

Headings by default have a padding of 0. However, by default an H1 for example has a top and bottom margin: .67em;. These top-bottom margins grow all the way to 2.33em for an H6. So for each heading, the top and bottom margins gradually increase by default.

Check out this helpful article by W3Schools which is insightful when discussing the defaults for all HTML elements.

So to answer your question. Yes, the padding: 0; is unnecessary. However, the margin: 0; will change the default top and bottom margins.

Related