Every font carries some empty space above the capitals and below the baseline. That is why a button with equal padding never looks centered, and text-box is, in my view, the long missing fix.
.button,
h1 {
text-box: trim-both cap alphabetic;
}
It is a shorthand for two properties. text-box-trim: trim-both says to trim at the top of the first line and the bottom of the last line. text-box-edge: cap alphabetic says where to cut: at the cap height of the font at the top and at the alphabetic baseline at the bottom. After that, padding: 0.75rem 1.25rem really means 0.75rem of space between the edge and the letters.
For headings it also helps with spacing to the element above, because the gap you set is the gap you see. If your text has many descenders like g and p, alphabetic lets them hang into the padding, so try text as the bottom edge if that looks cramped.
Support is fairly new: Chrome 133, Safari 18.2 and Firefox 154. Older browsers ignore the line and keep the normal line box, so nothing breaks. It is a nice progressive enhancement, but check the result in one older browser too, since the spacing there will be a bit larger.
Further reading: MDN: text-box, MDN: text-box-edge