3

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?

Kameron
  • 10,240
  • 4
  • 13
  • 26
FireFuro99
  • 357
  • 1
  • 5
  • 18

1 Answers1

6

Headings, by default, have a padding of 0. However, an H1 for example has a top and bottom margin: .67em;, by default. 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.

I usually only post from MDN, but unfortunately, they don't have anything on this. 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.

Kameron
  • 10,240
  • 4
  • 13
  • 26