View as Markdown
Pagination
Use the Tailwind CSS pagination element to indicate a series of content across various pages based on multiple styles and sizes
100%
Loading...
<twig:Pagination>
<twig:Pagination:Content>
<twig:Pagination:Item>
<twig:Pagination:Previous href="#" />
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">1</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#" active>2</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">3</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Next href="#" />
</twig:Pagination:Item>
</twig:Pagination:Content>
</twig:Pagination>
Installation
Note
Available since UX Toolkit 2.35.
php bin/console ux:install pagination --kit flowbite-4
Install the following Composer dependencies:
composer require symfony/ux-icons twig/html-extra:^3.24.0 symfony/ux-twig-component:^3.5 tales-from-a-dev/twig-tailwind-extra:^1.3.0
Install the following front-end dependencies:
npm install flowbite
# ...or with Symfony AssetMapper
php bin/console importmap:require flowbite
Copy the following file(s) into your app:
templates/components/Pagination.html.twig
<nav
role="navigation"
{{ attributes.defaults({
class: 'flex items-center space-x-4'|tailwind_classes,
}) }}
>
{##- The pagination structure, typically a `Pagination:Content`. -#}
{%- block content %}{% endblock -%}
</nav>
templates/components/Pagination/Content.html.twig
<ul
{{ attributes.defaults({
class: 'flex -space-x-px text-sm rounded-base [&_a]:h-10 [&_*]:rounded-none [&>*:first-child]:[&_*]:rounded-s-base [&>*:last-child]:[&_*]:rounded-e-base'|tailwind_classes,
}) }}
>
{##- The pagination items, typically multiple `Pagination:Item` components. -#}
{%- block content %}{% endblock -%}
</ul>
templates/components/Pagination/Item.html.twig
<li{{ attributes }}>
{##- The pagination item content, typically a `Pagination:Link`. -#}
{%- block content %}{% endblock -%}
</li>
templates/components/Pagination/Link.html.twig
{%- props
## boolean Whether this is the current page.
active = false
-%}
<twig:Button
as="a"
variant="secondary"
shape="rounded"
size="icon"
aria-current="{{ active ? 'page' : 'false' }}"
href="#"
class="{{ active ? 'text-fg-brand bg-neutral-tertiary-medium' : '' }}"
{{ ...attributes.without('class') }}
>
{##- The page number or navigation icon. -#}
{{- block(outerBlocks.content) -}}
</twig:Button>
templates/components/Pagination/Next.html.twig
{% props
## boolean Whether to render only the chevron icon instead of the text label.
asIcon = false
%}
<twig:Pagination:Link
aria-label="Go to next page"
size="{{ asIcon ? 'icon' : 'default' }}"
{{ ...attributes }}
>
{% if asIcon %}
<twig:ux:icon name="flowbite:chevron-right-outline" class="size-4" />
{% else %}
<span>Next</span>
{% endif %}
</twig:Pagination:Link>
templates/components/Pagination/Previous.html.twig
{% props
## boolean Whether to render only the chevron icon instead of the text label.
asIcon = false
%}
<twig:Pagination:Link
aria-label="Go to previous page"
size="{{ asIcon ? 'icon' : 'default' }}"
{{ ...attributes }}
>
{% if asIcon %}
<twig:ux:icon name="flowbite:chevron-left-outline" class="size-4" />
{% else %}
<span>Previous</span>
{% endif %}
</twig:Pagination:Link>
Usage
<twig:Pagination>
<twig:Pagination:Content>
<twig:Pagination:Item>
<twig:Pagination:Previous href="#" />
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">1</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#" active>2</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">3</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Next href="#" />
</twig:Pagination:Item>
</twig:Pagination:Content>
</twig:Pagination>
Examples
As icon
The following pagination component example shows how you can use SVG icons instead of text to show the previous and next pages.
100%
Loading...
<twig:Pagination>
<twig:Pagination:Content>
<twig:Pagination:Item>
<twig:Pagination:Previous asIcon href="#" />
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">1</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#" active>2</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Link href="#">3</twig:Pagination:Link>
</twig:Pagination:Item>
<twig:Pagination:Item>
<twig:Pagination:Next asIcon href="#" />
</twig:Pagination:Item>
</twig:Pagination:Content>
</twig:Pagination>
API Reference
<twig:Pagination>
| Block | Description |
|---|---|
content |
The pagination structure, typically a Pagination:Content. |
<twig:Pagination:Content>
| Block | Description |
|---|---|
content |
The pagination items, typically multiple Pagination:Item components. |
<twig:Pagination:Item>
| Block | Description |
|---|---|
content |
The pagination item content, typically a Pagination:Link. |
<twig:Pagination:Link>
| Prop | Type | Default |
|---|---|---|
active Whether this is the current page.
|
boolean |
false |
| Block | Description |
|---|---|
content |
The page number or navigation icon. |
<twig:Pagination:Next>
| Prop | Type | Default |
|---|---|---|
asIcon Whether to render only the chevron icon instead of the text label.
|
boolean |
false |
<twig:Pagination:Previous>
| Prop | Type | Default |
|---|---|---|
asIcon Whether to render only the chevron icon instead of the text label.
|
boolean |
false |