labsUI
Accent color

Comparison Table

Products, laptops, plans or ranks compared feature by feature, in groups, with a "differences only" switch. Checks and dashes carry text for screen readers. Wide, every item is a column, the names stay pinned at the top and the features at the left. Narrow, two pickers choose the items side by side and differences follow the two in view.

npx @kznlabs/labsui add comparison-table

Feature
Lumen 13
$899
Quill 14
$1,149
Harbor 15Popular
$1,399
Anvil 16
$1,899
Display
Size13.3 in14 in15.6 in16 in
Refresh rate60 Hz120 Hz120 Hz165 Hz
Touch screenNoYesYesNo
Matte finishYesYesYesYes
Performance
Memory16 GB16 GB32 GB64 GB
Storage512 GB1 TB1 TB2 TB
Dedicated graphicsNoNoYesYes
Ports
USB-C2222
HDMINoYesYesYes
Card readerNoNoYesYes
Headphone jackYesYesYesYes
Build
Weight1.1 kg1.4 kg1.8 kg2.3 kg
Battery14 h12 h10 h7 h
Backlit keyboardYesYesYesYes
Lumen 13
$899
Quill 14
$1,149
Display
Size
13.3 in14 in
Refresh rate
60 Hz120 Hz
Touch screen
NoYes
Matte finish
YesYes
Performance
Memory
16 GB16 GB
Storage
512 GB1 TB
Dedicated graphics
NoNo
Ports
USB-C
22
HDMI
NoYes
Card reader
NoNo
Headphone jack
YesYes
Build
Weight
1.1 kg1.4 kg
Battery
14 h12 h
Backlit keyboard
YesYes
import { ComparisonTable } from "@/components/blocks/comparison-table";import { buttonVariants } from "@/components/ui/button-variants";export function Laptops() {  return (    <ComparisonTable      label="Laptops compared"      stickyTop="3.5rem"      items={[        { id: "lumen", name: "Lumen 13", details: "$899" },        {          id: "harbor",          name: "Harbor 15",          details: "$1,399",          badge: "Popular",          featured: true,          action: (            <a className={buttonVariants({ size: "sm" })} href="/buy/harbor">              Buy            </a>          ),        },      ]}      groups={[        {          label: "Display",          rows: [            { label: "Size", values: { lumen: "13.3 in", harbor: "15.6 in" } },            { label: "Touch screen", values: { lumen: false, harbor: true } },          ],        },        {          label: "Ports",          rows: [{ label: "USB-C", values: { lumen: 2, harbor: 2 } }],        },      ]}    />  );}

<ComparisonTable>

A feature-by-feature comparison, grouped, that can show only the differences. Wide, every item is a column under a pinned header and beside a pinned feature column. Narrow, two pickers choose the items side by side, each feature's name above its values, and differences follow the two in view.

  • groups required
    ComparisonGroup[]
    Grouped rows in display order.
  • items required
    ComparisonItem[]
    Columns in display order.
  • columnLabelDefault "Column"
    string
    Names the column pickers on a narrow screen, before the column's number.
  • countLabelDefault (shown, total) => `${shown} of ${total} rows`
    (shown: number, total: number) => string
    Text beside the switch while it is on. Call it from a client parent to translate.
  • defaultDifferencesOnlyDefault false
    boolean
    "Differences only" at first render (uncontrolled).
  • differencesLabelDefault "Differences only"
    string
    Text on the switch.
  • differencesOnly
    boolean
    Controlled "differences only"; pair with onDifferencesOnlyChange.
  • differencesToggleDefault true
    boolean
    Shows the switch. Turn it off for a short table, or when your own control sets differencesOnly.
  • emptyLabelDefault "Every row is the same."
    ReactNode
    Shown when every row is the same.
  • featureLabelDefault "Feature"
    string
    Read by screen readers as the heading of the feature column.
  • labelDefault "Comparison"
    string
    Names the table for screen readers.
  • noLabelDefault "No"
    string
    Read by screen readers on a dash.
  • onDifferencesOnlyChange
    (differencesOnly: boolean) => void
    Called with the new "differences only" state.
  • stickyTopDefault "0px"
    string
    How far below the top of the page the header pins, as a CSS length. Pass your sticky site header's height.
  • yesLabelDefault "Yes"
    string
    Read by screen readers on a check.
PropTypeDefault
groups required
Grouped rows in display order.
ComparisonGroup[]—
items required
Columns in display order.
ComparisonItem[]—
columnLabel
Names the column pickers on a narrow screen, before the column's number.
string"Column"
countLabel
Text beside the switch while it is on. Call it from a client parent to translate.
(shown: number, total: number) => string(shown, total) => `${shown} of ${total} rows`
defaultDifferencesOnly
"Differences only" at first render (uncontrolled).
booleanfalse
differencesLabel
Text on the switch.
string"Differences only"
differencesOnly
Controlled "differences only"; pair with onDifferencesOnlyChange.
boolean—
differencesToggle
Shows the switch. Turn it off for a short table, or when your own control sets differencesOnly.
booleantrue
emptyLabel
Shown when every row is the same.
ReactNode"Every row is the same."
featureLabel
Read by screen readers as the heading of the feature column.
string"Feature"
label
Names the table for screen readers.
string"Comparison"
noLabel
Read by screen readers on a dash.
string"No"
onDifferencesOnlyChange
Called with the new "differences only" state.
(differencesOnly: boolean) => void—
stickyTop
How far below the top of the page the header pins, as a CSS length. Pass your sticky site header's height.
string"0px"
yesLabel
Read by screen readers on a check.
string"Yes"

required

Also accepts every <div> prop.

type ComparisonItem
{ id: string; name: string; href?: string; media?: ReactNode; details?: ReactNode; action?: ReactNode; badge?: string; featured?: boolean; }
type ComparisonGroup
{ label: string; rows: ComparisonRow[]; }

Every component also takes className.