Explain Codes LogoExplain Codes Logo

What are the most common font-sizes for H1-H6 tags

html
responsive-design
css
font-sizes
Alex KataevbyAlex Kataev·Sep 17, 2024
TLDR

Typically, font-sizes for H1 to H6 HTML tags decrease sequentially:

  • H1: 32px
  • H2: 24px
  • H3: 19px
  • H4: 16px
  • H5: 14px
  • H6: 12px

These sizes aim to balance design aesthetics and readability, forming a visual hierarchy.

Generally, `H1` to `H6` tags decrease in size: - `H1`: **32px** - `H2`: **24px** - `H3`: **19px** - `H4`: **16px** - `H5`: **14px** - `H6`: **12px** These measurements strike a balance between aesthetic design and readability while establishing a visual hierarchy.

Understand the importance of browser defaults

In programming, the concept of defaults is paramount. This extends to default stylesheets embedded in browsers. These default styles, though varying slightly in older versions like IE7, IE8, FF2, FF3, and Opera, provide a universal starting point.

To achieve consistent user experience and design harmony, first understand these defaults and then customize to suit your design philosophy. Remember, accessibility shouldn't be compromised; font sizes should remain legible for all users.

Speaking of design philosophy, some embrace pixels (px) for font sizes, things being absolute and all, but modern design says hold my beer…

Digging into CSS units for scalable design

Enter the world of responsive design practices where EMs and REMs celebrate scalability and accessibility. The fixed position of pixels gives way to dynamics, a rhythm that adapts to screen sizes and user preferences.

Defining font sizes with EMs and REMs

/* Welcome to CSS, where selenophiles code at night 🌙 */ body { /* Hey REM, you're now the Nick Fury of font size */ font-size: 16px; /* The base size makes the REM equivalent to pixel size */ } h1 { font-size: 2rem; /* 32px, huge like the Hulk 💪 */ } h2 { font-size: 1.5rem; /* 24px, tough like Thor ⚡ */ } h3 { font-size: 1.1875rem; /* 19px, agile like Ant-Man 🐜 */ } h4 { font-size: 1rem; /* 16px, on point like Hawkeye 🏹 */ } h5 { font-size: 0.875rem; /* 14px, spry like Spiderman 🕸️ */ } h6 { font-size: 0.75rem; /* 12px, stealthy like Black Widow 🕷️ */ }

All your headlines are now true Avengers on your site, expanding with the viewport or shrinking for small devices, always in proportion to the body font size.

The magic trick of CSS custom properties

Defining a CSS Custom Property, such as --headline-font-size, allows global adjustments across multiple components. Now your design updates are as swift as Quicksilver!

Striking a balance with cross-browser consistency

Different browsers, different default sizes. An old song that every developer knows, but there are modern solutions, such as browser reset or normalization stylesheets.

These strategies help achieve consistency, minimizing the discrepancies and setting a smooth baseline. So even when the chorus changes, the rhythm stays the same.

When consistency meets flair, we have adaptive font sizing and fluid typography techniques. Here, the font sizes morph with the viewport dimensions. This magic show uses a combination of viewport units (vw/vh), calc(), media queries, and CSS clamp() function.

Last but not least, a design tip: going bold is always a power move, but sometimes, just sometimes, disabling bold on headers might win you the day, making your words "the silent hero".