Spaces around h1 tags

Posted on August 11, 2021
Updated on August 15, 2021

EDIT: Apparently, the behaviour below is consistent between Firefox and Chromium for links, but not for <h1>. My conclusion is that the <h1> behaviour is a Firefox quirk, but the <a> is expected.


The HTML below has selectable extra spaces after <h1> tags:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Spaces around h1 tags</title>
  </head>
  <body>
    <main>
      <h1>
        With spaces around when selecting this heading
      </h1>
      <h1>Without spaces around</h1>
      <p>
        Is this expected behaviour?
      </p>
    </main>
  </body>
</html>

The rendered output is:

With spaces around when selecting this heading

Without spaces around

Is this expected behaviour?


The same with links:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Spaces after a tags</title>
  </head>
  <body>
    <main>
      <p>
        <a href="#">
          With extra underlined space
        </a>
      </p>
      <p>
        <a href="#">Without extra underlined space</a>
      </p>
    </main>
  </body>
</html>

The rendered output is:

With extra underlined space after the link.

Without extra underlined space after the link.