Key Value
Data Display
Utility
Display key-value pairs with optional copy functionality, layouts, and monospace formatting for technical data.
Preview
Simple key-value pair display
NameJohn Doe
Emailjohn@example.com
StatusActive
Layouts
Horizontal, vertical, and inline layouts
Horizontal (default)
API Key:sk-1234-5678-abcd
Region:us-east-1
Vertical
API Keysk-1234-5678-abcd
Regionus-east-1
Inline
Version:2.4.1
License:MIT
Downloads:12.5k
With Copy Button
Allow users to copy values to clipboard
API Keysk-1234-5678-abcd-efgh
Secret••••••••••••••••
Endpointhttps://api.example.com/v1
Monospace Values
Use monospace font for codes, IDs, and technical values
Task IDtsk_2x8k4m
Project IDprj_8x2k9m
User IDusr_7k2m9x4n
Sizes
Small, medium, and large text sizes
Small
EnvironmentProduction
Medium (default)
EnvironmentProduction
Large
EnvironmentProduction
Key Value Group
Group multiple key-value pairs together
Server Details
Hostsrv-01.example.com
IP Address192.168.1.100
StatusRunning
Uptime45 days, 12 hours
Divided Group
Add dividers between items for visual separation
Task Details
Task IDtsk_2x8k4m
ProjectMarketing Strategy
PriorityHigh
Due DateJanuary 15, 2025
Real-world Example
API credentials panel
API Credentials
Use these credentials to authenticate API requests
API Keypk_live_51MqLs92eZvKYlo2C
Secret Keysk_live_••••••••••••••••
Webhook URLhttps://api.myapp.com/webhooks/stripe
Keep your secret key private. Never share it in public repositories.
Props
Component API reference
KeyValue Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | The key/label (required) |
value | ReactNode | — | The value (required) |
layout | 'horizontal' | 'vertical' | 'inline' | 'horizontal' | Layout direction |
size | 'sm' | 'md' | 'lg' | 'md' | Text size |
copyable | boolean | false | Show copy button |
copyValue | string | — | Value to copy (if different from display) |
mono | boolean | false | Use monospace font for value |
showColon | boolean | true | Show colon after label |
className | string | — | Additional CSS classes |
KeyValueGroup Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | KeyValueItem[] | — | Array of KeyValue props (required) |
layout | 'horizontal' | 'vertical' | 'horizontal' | Layout for all items |
divided | boolean | false | Add dividers between items |
spacing | 'sm' | 'md' | 'lg' | 'sm' | Spacing between items |
className | string | — | Additional CSS classes |
Usage
Import and implementation example
import { KeyValue, KeyValueGroup } from '@/components/ui/key-value'
export default function Example() { return ( <> {/* Basic key-value */} <KeyValue label="Name" value="John Doe" />
{/* With copy button */} <KeyValue label="API Key" value="sk-1234-5678" copyable />
{/* Monospace value */} <KeyValue label="ID" value="#ORD-001" mono />
{/* Different layouts */} <KeyValue layout="horizontal" label="Key" value="Value" /> <KeyValue layout="vertical" label="Key" value="Value" /> <KeyValue layout="inline" label="Key" value="Value" />
{/* Different sizes */} <KeyValue size="sm" label="Small" value="Value" /> <KeyValue size="md" label="Medium" value="Value" /> <KeyValue size="lg" label="Large" value="Value" />
{/* Key Value Group */} <KeyValueGroup items={[ { label: 'Name', value: 'John' }, { label: 'Email', value: 'john@example.com', copyable: true }, ]} />
{/* Divided group */} <KeyValueGroup divided spacing="md" items={items} />
{/* Copy different value than displayed */} <KeyValue label="Secret" value="••••••••" copyable copyValue="actual-secret-value" /> </> )}Features
Built-in functionality
- Three layouts: Horizontal, vertical, and inline options
- Copy to clipboard: Built-in copy functionality with feedback
- Masked copy: Display masked value but copy the real one
- Monospace option: Use monospace font for technical values
- Size variants: Small, medium, and large text sizes
- Group component: KeyValueGroup for multiple items
- Dividers: Optional dividers between group items
- Dark mode: Full dark mode support
Accessibility
Accessibility considerations
ARIA Attributes
Uses semantic dl/dt/dd elements for key-value pairsCopy button has proper aria-labelCopy success announced to screen readersKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Navigate to copy buttons |
| Enter / Space | Activate copy |
Notes
- Labels are associated with their values
- Copy confirmation is both visual and announced
- Monospace font improves readability for codes