Heading

Typography

Semantic heading with level and size variants.

Preview

Heading Level 1

Heading Level 2

Heading Level 3

Heading Level 4

Usage

example.jsx
import { Heading } from "@/components/ui/heading";

export default function Example() {
  return <Heading />;
}

Source Code

Copy this file into components/ui/heading.jsx in your project.

heading.jsx
import { forwardRef } from "react";
import { cn } from "@/lib/utils";

const levels = {
  1: "scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl",
  2: "scroll-m-20 text-3xl font-semibold tracking-tight",
  3: "scroll-m-20 text-2xl font-semibold tracking-tight",
  4: "scroll-m-20 text-xl font-semibold tracking-tight",
  5: "scroll-m-20 text-lg font-semibold tracking-tight",
  6: "scroll-m-20 text-base font-semibold tracking-tight",
};

const Heading = forwardRef(({ className, level = 1, as, ...props }, ref) => {
  const Tag = as || `h${level}`;
  return <Tag ref={ref} className={cn(levels[level], className)} {...props} />;
});
Heading.displayName = "Heading";

export { Heading };

Quick Install

Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.

npm install clsx tailwind-merge