data
Styled data tables (table[table]) and horizontally scrolling DataTable frames
Use Table(..., table=True) for a styled table with caption, thead, tbody, and tfoot. DataTable wraps that table in a bordered, raised frame ([table-frame]). Inside DataTable, cells stay on one line and the frame scrolls horizontally when the table is wider than its parent container.
from fasthtml.common import *
from answerui.demo import demo
from fastcore.test import *
Tables
When you pass table=True to Table, thead th and tfoot th are semibold (--weight1), with horizontal borders under the header and between body and footer rows. Any caption appears below the table in muted --text-1 text. Add num=True to a Th or Td to align it to the end with tabular digits (font-variant-numeric: tabular-nums). Inside [prose], the prose stylesheet formats unmarked table elements with .875em text and prose spacing.
DataTable wraps Table(*c, table=True) in a Div with table_frame=True ([table-frame]). That container has a border, a --raised shadow, overflow-x: auto, and contain: inline-size. Because of contain: inline-size, a wide table scrolls inside the frame rather than widening the page or its containing card. Inside [table-frame], thead th has a --color-surface background and cells stay on one line (white-space: nowrap). Keyword attributes passed to DataTable apply to the outer Div. For keyboard scrolling, pass role='region', tabindex=0, and aria_label on DataTable. Focused frames show the --ring outline ([table-frame]:focus-visible).
DataTable
def DataTable(
*c, **attrs
):
A table in a bordered frame that scrolls when its contents are wider than its container
Here is a quarterly regional summary using Caption, num=True on numeric cells, and totals in Tfoot:
DataTable.demo()
Summary list
SummaryList renders an opt-in key-value <dl summary-list> of <div><dt>...</dt><dd>...</dd></div> rows with hairline dividers and an optional trailing action <dd>. Each tuple (key, value) or (key, value, action) becomes one row; pass raw Div(...) elements for custom row attributes. Rows stack cleanly in narrow containers (< 28rem) via a container query.
SummaryList
def SummaryList(
*rows, **attrs
):
A hairline-divided key-value <dl> with optional trailing action per row
SummaryList.demo()