Headers size and usage recommendations in Tailwind CSS

Use headers to create a clear hierarchy and structure in your content. Stick the header level to predefined Tailwind CSS classes sizes(e.g., text-xl to text-4xl) to maintain consistency and visual appeal.

Here are the recommended font sizes:

TagRecommended ClassFont Size (rem)Font Size (px)
h1text-4xl2.25036
h2text-3xl1.87530
h3text-2xl1.50024
h4text-xl1.25020
h5text-lg1.12518
h6text-base (bold)1.00016
ptext-base1.00016
h7*text-sm (uppercase)0.87514
TagRecommended Use CaseStrategy
h1The Page TitleThe main topic. Use only one per page. Essential for SEO.
h2Section HeadingsMajor chapters of your content (e.g., "Features," "Pricing").
h3Sub-sectionsBreaks down an h2 into smaller parts (e.g., "Monthly" under "Pricing").
h4Group HeadingsLabels for UI cards, sidebar widgets, or small content blocks.
h5Detail LabelsMicro-headers for specific metadata or very small card titles.
h6Captions/LegalsThe lowest level, often used for "Related Posts" or footer headings.

Spacing between headers

In typography, the space above a header (top margin) should always be larger than the space below it (bottom margin). This creates "proximity," visually grouping the header with the content it belongs to.

The "2:1 Rule" for Headings: make the top margin roughly double the bottom margin.

TagTop Margin (MT)Bottom Margin (MB)Tailwind Classes
H1mt-0mb-6mt-0 mb-6
H2mt-12mb-6mt-12 mb-6
H3mt-10mb-4mt-10 mb-4
H4mt-8mb-4mt-8 mb-4
P (Body)mt-0mb-6mb-6

Website name

Recommended Font Sizes for the Website Name

If you are not using a header tag and need to style a <div> or <span> for your site name, use these Tailwind-equivalent sizes:

General Rule: The site name should be visually distinct but smaller or equal in visual weight to the page's main <h1> title so the user knows exactly where they are

DeviceRecommended Tailwind ClassEquivalent Pixels
Mobiletext-xl to text-2xl20px - 24px
Desktoptext-2xl to text-3xl24px - 30px

For SEO

  1. Homepage: Google sees <h1>MyBrand</h1>. This tells the crawler that "MyBrand" is the most important topic of the root domain.
  2. Inner Pages: Google sees <span>MyBrand</span> in the nav, but finds <h1>Our Services</h1> in your main content. This prevents "keyword cannibalization" where your brand name competes with your actual page topics.

Switching tag code for Next.js 14

Code: Logo.jsx
// components/Logo.jsx
import Link from 'next/link';
import { useRouter } from 'next/router';
const Logo = () => {
const router = useRouter();
// Check if current path is exactly the homepage
const isHomePage = router.pathname === '/';
// Dynamic tag: h1 for SEO on home, span for inner pages
const Tag = isHomePage ? 'h1' : 'span';
return (
<Link href="/" className="inline-block">
<Tag className="text-xl font-bold tracking-tight text-gray-900 md:text-2xl lg:text-3xl">
MyBrand<span className="text-indigo-600">.</span>
</Tag>
</Link>
);
};
export default Logo;
Code: Header.jsx
// components/Header.jsx
import Logo from './Logo';
export default function Header() {
return (
<header className="flex items-center justify-between px-6 py-4 bg-white border-b border-gray-100">
<Logo />
<nav className="hidden md:flex space-x-8 text-sm font-medium">
<a href="/features" className="hover:text-indigo-600">Features</a>
<a href="/pricing" className="hover:text-indigo-600">Pricing</a>
</nav>
</header>
);
}
Code: Layout.jsx
// components/Layout.jsx
import Header from './Header'; // This should contain your Logo component
export default function Layout({ children }) {
return (
<div className="min-h-screen bg-gray-50 text-gray-900">
<Header />
<main className="container mx-auto px-4 py-8">
{children}
</main>
<footer className="p-4 text-center text-sm text-gray-500">
© {new Date().getFullYear()} MyBrand. All rights reserved.
</footer>
</div>
);
}
Code: _app.js
// pages/_app.js
import Layout from '../components/Layout';
export default function MyApp({ Component, pageProps }) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
);
}