React Tables - Flowbite
Get started with the table component to show data such as text, numbers, images, and links using a structured set of data based on rows and columns based on React
Table of Contents#
Default table#
Use this example to show a responsive table component with table head and body featuring cells and rows on multiple levels by using the <Table>
React component and the children components such as <Table.Head>
, <Table.Body>
, <Table.Row>
and <Table.Cell>
.
- React TypeScript
'use client';
import { Table } from 'flowbite-react';
export default function DefaultTable() {
return (
<Table>
<Table.Head>
<Table.HeadCell>
Product name
</Table.HeadCell>
<Table.HeadCell>
Color
</Table.HeadCell>
<Table.HeadCell>
Category
</Table.HeadCell>
<Table.HeadCell>
Price
</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">
Edit
</span>
</Table.HeadCell>
</Table.Head>
<Table.Body className="divide-y">
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Apple MacBook Pro 17"
</Table.Cell>
<Table.Cell>
Sliver
</Table.Cell>
<Table.Cell>
Laptop
</Table.Cell>
<Table.Cell>
$2999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>
Microsoft Surface Pro
</p>
</Table.Cell>
<Table.Cell>
White
</Table.Cell>
<Table.Cell>
Laptop PC
</Table.Cell>
<Table.Cell>
$1999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Magic Mouse 2
</Table.Cell>
<Table.Cell>
Black
</Table.Cell>
<Table.Cell>
Accessories
</Table.Cell>
<Table.Cell>
$99
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
)
}
Striped rows#
Use the striped
React prop on the <Table>
component to alternate the background of every second row of the table to increase contrast and readability.
- React TypeScript
'use client';
import { Table } from 'flowbite-react';
export default function StripedRows() {
return (
<Table striped>
<Table.Head>
<Table.HeadCell>
Product name
</Table.HeadCell>
<Table.HeadCell>
Color
</Table.HeadCell>
<Table.HeadCell>
Category
</Table.HeadCell>
<Table.HeadCell>
Price
</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">
Edit
</span>
</Table.HeadCell>
</Table.Head>
<Table.Body className="divide-y">
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Apple MacBook Pro 17"
</Table.Cell>
<Table.Cell>
Sliver
</Table.Cell>
<Table.Cell>
Laptop
</Table.Cell>
<Table.Cell>
$2999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>
Microsoft Surface Pro
</p>
</Table.Cell>
<Table.Cell>
White
</Table.Cell>
<Table.Cell>
Laptop PC
</Table.Cell>
<Table.Cell>
$1999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Magic Mouse 2
</Table.Cell>
<Table.Cell>
Black
</Table.Cell>
<Table.Cell>
Accessories
</Table.Cell>
<Table.Cell>
$99
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>
Google Pixel Phone
</p>
</Table.Cell>
<Table.Cell>
Gray
</Table.Cell>
<Table.Cell>
Phone
</Table.Cell>
<Table.Cell>
$799
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Apple Watch 5
</Table.Cell>
<Table.Cell>
Red
</Table.Cell>
<Table.Cell>
Wearables
</Table.Cell>
<Table.Cell>
$999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
)
}
Table hover state#
Add the hoverable
prop to the <Table>
React component to show a hover effect when moving the mouse over a table row. This also helps with readability.
- React TypeScript
'use client';
import { Table } from 'flowbite-react';
export default function HoverState() {
return (
<Table hoverable>
<Table.Head>
<Table.HeadCell>
Product name
</Table.HeadCell>
<Table.HeadCell>
Color
</Table.HeadCell>
<Table.HeadCell>
Category
</Table.HeadCell>
<Table.HeadCell>
Price
</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">
Edit
</span>
</Table.HeadCell>
</Table.Head>
<Table.Body className="divide-y">
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Apple MacBook Pro 17"
</Table.Cell>
<Table.Cell>
Sliver
</Table.Cell>
<Table.Cell>
Laptop
</Table.Cell>
<Table.Cell>
$2999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>
Microsoft Surface Pro
</p>
</Table.Cell>
<Table.Cell>
White
</Table.Cell>
<Table.Cell>
Laptop PC
</Table.Cell>
<Table.Cell>
$1999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Magic Mouse 2
</Table.Cell>
<Table.Cell>
Black
</Table.Cell>
<Table.Cell>
Accessories
</Table.Cell>
<Table.Cell>
$99
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
)
}
Table with checkboxes#
Use this example to show multiple checkbox form elements for each table row that you can use when performing bulk actions.
- React TypeScript
'use client';
import { Checkbox, Table } from 'flowbite-react';
export default function Checkbox() {
return (
<Table hoverable>
<Table.Head>
<Table.HeadCell className="p-4">
<Checkbox />
</Table.HeadCell>
<Table.HeadCell>
Product name
</Table.HeadCell>
<Table.HeadCell>
Color
</Table.HeadCell>
<Table.HeadCell>
Category
</Table.HeadCell>
<Table.HeadCell>
Price
</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">
Edit
</span>
</Table.HeadCell>
</Table.Head>
<Table.Body className="divide-y">
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="p-4">
<Checkbox />
</Table.Cell>
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Apple MacBook Pro 17"
</Table.Cell>
<Table.Cell>
Sliver
</Table.Cell>
<Table.Cell>
Laptop
</Table.Cell>
<Table.Cell>
$2999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="p-4">
<Checkbox />
</Table.Cell>
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>
Microsoft Surface Pro
</p>
</Table.Cell>
<Table.Cell>
White
</Table.Cell>
<Table.Cell>
Laptop PC
</Table.Cell>
<Table.Cell>
$1999
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
<Table.Cell className="p-4">
<Checkbox />
</Table.Cell>
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
Magic Mouse 2
</Table.Cell>
<Table.Cell>
Black
</Table.Cell>
<Table.Cell>
Accessories
</Table.Cell>
<Table.Cell>
$99
</Table.Cell>
<Table.Cell>
<a
className="font-medium text-cyan-600 hover:underline dark:text-cyan-500"
href="/tables"
>
<p>
Edit
</p>
</a>
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
)
}
Theme#
To learn more about how to customize the appearance of components, please see the Theme docs.
{
"root": {
"base": "w-full text-left text-sm text-gray-500 dark:text-gray-400",
"shadow": "absolute bg-white dark:bg-black w-full h-full top-0 left-0 rounded-lg drop-shadow-md -z-10",
"wrapper": "relative"
},
"body": {
"base": "group/body",
"cell": {
"base": "group-first/body:group-first/row:first:rounded-tl-lg group-first/body:group-first/row:last:rounded-tr-lg group-last/body:group-last/row:first:rounded-bl-lg group-last/body:group-last/row:last:rounded-br-lg px-6 py-4"
}
},
"head": {
"base": "group/head text-xs uppercase text-gray-700 dark:text-gray-400",
"cell": {
"base": "group-first/head:first:rounded-tl-lg group-first/head:last:rounded-tr-lg bg-gray-50 dark:bg-gray-700 px-6 py-3"
}
},
"row": {
"base": "group/row",
"hovered": "hover:bg-gray-50 dark:hover:bg-gray-600",
"striped": "odd:bg-white even:bg-gray-50 odd:dark:bg-gray-800 even:dark:bg-gray-700"
}
}