Examples

Default (2 columns)

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500
Payment method
Credit Card, UPI
Valid from
01 Jun 2026
Valid till
30 Jun 2026
Min order value
₹1,499
Usage limit
1 per customer

Three columns

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500
Payment method
Credit Card, UPI
Valid from
01 Jun 2026
Valid till
30 Jun 2026
Min order value
₹1,499
Usage limit
1 per customer

Single column

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500
Payment method
Credit Card, UPI

Sizes

Three typography presets — sm (14/12px), md (16/14px, default), and lg (18/16px) — scale the text. The value sits 2px below the label so the key reads as the primary element.

size="sm"

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500

size="md"

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500

size="lg"

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500

Horizontal layout

Set layout="horizontal" to place each label beside its value.

Offer name
Summer Sale 2026
Offer code
SUMMER20
Discount
20% off, up to ₹500
Payment method
Credit Card, UPI
Valid from
01 Jun 2026

Empty values hidden (default)

Items whose value is null, undefined, or an empty string are skipped — the "Phone" and "Notes" rows below disappear.

Customer
Neha Sanwal
Email
neha@example.com
Wallet balance
₹2,340

Empty values shown

Pass hideEmpty=false with an emptyText placeholder.

Customer
Neha Sanwal
Email
neha@example.com
Phone
N/A
Notes
N/A
Wallet balance
₹2,340

Custom value snippet

Render the value cell yourself — here the "Status" field uses a Pill.

Offer name
Festive Cashback
Status
active
Channel
Online
Created by
Merchant Ops

Documentation

A read-only label/value grid for rendering detail views — offer summaries, customer profiles, order metadata, and similar "field: value" layouts. Pairs flow row-major across a configurable number of columns, collapsing to a single column on narrow screens. Empty values are skipped by default (so optional fields disappear cleanly), and either side can be fully customised with a snippet for rendering tags, links, avatars, or formatted values. For a single prominent metric with a delta badge and dashboard framing, use StatCard instead.

Horizontal layouts reduce their column count in narrow host containers, including desktop sidebars. Long labels and values wrap inside each pair.

Usage

<script>
  import { KeyValue } from '@juspay/svelte-ui-components';

  const fields = [
    { label: 'Offer name', value: 'Summer Sale 2026' },
    { label: 'Status', value: 'Active' },
    { label: 'Discount', value: '20% off' },
    { label: 'Valid till', value: '30 Jun 2026' }
  ];
</script>

<KeyValue items={fields} />

Columns

Set how many columns the pairs flow across with columns (default 2). The grid automatically collapses to a single column below 600px wide.

<KeyValue items={fields} columns={3} />

Sizes

Three typography presets scale the text, with the value 2px smaller than the label so the key reads as the primary element: sm (14/12px), md (16/14px, default), and lg (18/16px) — label/value respectively. Individual --keyvalue-label-size / --keyvalue-value-size overrides always win over the preset.

<KeyValue items={fields} size="sm" />
<KeyValue items={fields} size="md" />
<KeyValue items={fields} size="lg" />

Horizontal layout

Use layout="horizontal" to place each label beside its value instead of above it. The label column width is controlled by the --keyvalue-label-width CSS variable.

<KeyValue items={fields} layout="horizontal" columns={1} />

Empty values

By default (hideEmpty), items whose value is null, undefined, or an empty/whitespace string are omitted — optional fields simply disappear. Set hideEmpty={false} to render them as emptyText (default '—') instead.

<!-- The "Notes" row is hidden -->
<KeyValue
  items={[
    { label: 'Notes', value: '' },
    { label: 'Owner', value: 'Neha' }
  ]}
/>

<!-- The "Notes" row renders as "N/A" -->
<KeyValue items={[{ label: 'Notes', value: '' }]} hideEmpty={false} emptyText="N/A" />

Custom value rendering

Pass a valueSnippet to render the value cell yourself — useful for status pills, links, or formatted numbers. It receives (item, index).

<script>
  import { KeyValue, Pill } from '@juspay/svelte-ui-components';

  const fields = [
    { label: 'Offer name', value: 'Summer Sale' },
    { label: 'Status', value: 'active' }
  ];
</script>

<KeyValue items={fields}>
  {#snippet valueSnippet(item)}
    {#if item.label === 'Status'}
      <Pill text={item.value} />
    {:else}
      {item.value}
    {/if}
  {/snippet}
</KeyValue>

A labelSnippet is available for the same purpose on the label side.

Theming with Classes

Define a class that overrides the KeyValue CSS variables and pass it via classes:

/* app.css */
.compact-details {
  --keyvalue-row-gap: 8px;
  --keyvalue-label-color: #6b7280;
  --keyvalue-value-size: 13px;
}
<KeyValue items={fields} classes="compact-details" />

Props

Prop Type Required Default Description
items KeyValueItem[] Yes - The label/value pairs to render. Each item is { label, value?, testId?, title? }.
columns number No 2 Number of columns the pairs flow across (row-major). Collapses to one column on narrow screens.
layout 'vertical' | 'horizontal' No 'vertical' 'vertical' stacks the value under the label; 'horizontal' places them side-by-side.
size 'sm' | 'md' | 'lg' No 'md' Typography preset scaling label/value font sizes: sm 14/12px, md 16/14px, lg 18/16px (value 2px below label).
hideEmpty boolean No true When true, items with a null/undefined/empty value are omitted.
emptyText string No '—' Placeholder shown for empty values when hideEmpty is false.
valueSnippet Snippet<[KeyValueItem, number]> No - Custom renderer for the value cell, receiving (item, index). Falls back to plain text.
labelSnippet Snippet<[KeyValueItem, number]> No - Custom renderer for the label cell, receiving (item, index). Falls back to plain text.
testId string No - Value for the data-pw attribute on the root grid, used for end-to-end testing selectors.
classes string No - CSS class string applied to the root grid, for theming via class-scoped CSS variable overrides.

KeyValueItem

Field Type Required Description
label string Yes The field label (the "key").
value string | number | null No The field value. Empty values are skipped when hideEmpty is true.
title string No Tooltip on the value cell (native title).
testId string No Per-item test id, emitted as data-pw on the item wrapper.

Snippets

Snippet Args Description
valueSnippet (item, index) Replaces the default text rendering of the value cell.
labelSnippet (item, index) Replaces the default text rendering of the label cell.

CSS Variables

Override these custom properties to theme the component.

Variable Default CSS Property Description
--keyvalue-column-gap 32px column-gap Horizontal gap between columns.
--keyvalue-row-gap 16px row-gap Vertical gap between rows.
--keyvalue-pair-gap 4px (vertical layout), 12px (horizontal layout) gap Gap between a label and its value within an item.
--keyvalue-label-color #1a1a1a color Label text color.
--keyvalue-label-size size-based font-size Label font size. Defaults to the size preset (14/16/18px) unless set.
--keyvalue-label-weight 600 font-weight Label font weight.
--keyvalue-label-line-height 1.4 line-height Label line height.
--keyvalue-label-width 140px flex-basis Label column width in horizontal layout.
--keyvalue-label-flex 0 0 <label-width> flex Label cell's flex in horizontal layout. e.g. 1 1 0 for a label that takes the free space and truncates.
--keyvalue-value-flex 1 1 auto flex Value cell's flex in horizontal layout. e.g. 0 0 auto for a value sized to its content on the right.
--keyvalue-value-color #555 color Value text color.
--keyvalue-value-size size-based font-size Value font size. Defaults to the size preset (12/14/16px) unless set.
--keyvalue-value-weight 400 font-weight Value font weight.
--keyvalue-value-line-height 1.4 line-height Value line height.
--keyvalue-value-font-family inherit font-family Value font family.
--keyvalue-value-text-align inherit text-align Value alignment.
--keyvalue-value-font-variant-ligatures inherit font-variant Value ligatures.

Web Component

Svelte-only: valueSnippet (receives KeyValueItem, number), labelSnippet (receives KeyValueItem, number) take arguments, so they cannot be expressed as a named slot: a Web Component <slot> projects markup, it does not forward Svelte snippet parameters, so the arguments above would be silently dropped. Use the Svelte component directly when you need these.