Skip to the content
human-kit design
51 — Data display

Description List

Facts about one thing, each a term and its value, side by side or one over the other.

Patient
María Fernanda Ruiz
Date of birth
12 March 1988
Treatment
Frozen embryo transfer
Doctor
Dr. Ana Ramírez

Installation

pnpm dlx @human-kit/design add description-list
npx @human-kit/design add description-list
yarn dlx @human-kit/design add description-list
bunx @human-kit/design add description-list

The command copies the files to src/lib/components/ui/description-list. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as DescriptionList from '$lib/components/ui/description-list';
</script>

<DescriptionList.Root>
	<DescriptionList.Item>
		<DescriptionList.Term>Patient</DescriptionList.Term>
		<DescriptionList.Details>María Fernanda Ruiz</DescriptionList.Details>
	</DescriptionList.Item>
</DescriptionList.Root>

Guidelines

  • Use a description list for the facts of one thing: a patient, an invoice, an order. For many things with the same facts, use a table.
  • Use the horizontal layout where there is width: the terms line up in a column and the eye runs down the values.
  • Use vertical in a narrow column, a side panel or a card, where a column of terms would leave the values no room.
  • Turn divided on for a long list read row by row. Five facts or fewer read well without lines.
  • Set termWidth to the longest term, so no term wraps and the values start close to them.
  • Write an empty value as a dash or as "Not given", never as a blank: a blank reads as a fact still loading.

Accessibility

  • It renders a native <dl>, with each term in a <dt> and each value in a <dd>, so a screen reader reads each value with its term.
  • Item is a <div> around one pair, which HTML allows inside a <dl> and which keeps the pair together in the layout.
  • A term with more than one value takes several Details in the same Item.
  • The order in the code is the order read aloud: the term always comes before its value, in both layouts.

API reference

DescriptionList.Root

PropTypeDefault
layout'horizontal' | 'vertical'

The terms in a column beside the values, or each term over its value.

'horizontal'
dividedboolean

A thin line between the items. Rows grow from 24px to 32px.

false
termWidthstring

The width of the terms column, in the horizontal layout. Any CSS length.

'8rem'

Plus every attribute of a <dl>.

DescriptionList.Item

PropTypeDefault
classstring

Classes merged onto the row.

—

Plus every attribute of a <div>. It reads the layout of the root, so it has no props of its own.

DescriptionList.Term

PropTypeDefault
classstring

Classes merged onto the term.

—

Plus every attribute of a <dt>.

DescriptionList.Details

PropTypeDefault
classstring

Classes merged onto the value.

—

Plus every attribute of a <dd>.