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

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
{# @block content The pagination structure, typically a `Pagination:Content`. #}
<nav
    role="navigation"
    {{ attributes.defaults({
        class: 'flex items-center space-x-4'|tailwind_classes,
    }) }}
>
    {%- block content %}{% endblock -%}
</nav>
templates/components/Pagination/Content.html.twig
{# @block content The pagination items, typically multiple `Pagination:Item` components. #}
<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,
    }) }}
>
    {%- block content %}{% endblock -%}
</ul>
templates/components/Pagination/Item.html.twig
{# @block content The pagination item content, typically a `Pagination:Link`. #}
<li{{ attributes }}>
    {%- block content %}{% endblock -%}
</li>
templates/components/Pagination/Link.html.twig
{# @prop active boolean Whether this is the current page. #}
{# @block content The page number or navigation icon. #}
{%- props 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') }}
>
    {{- block(outerBlocks.content) -}}
</twig:Button>
templates/components/Pagination/Next.html.twig
{# @prop asIcon boolean Whether to render only the chevron icon instead of the text label. #}
{% props 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
{# @prop asIcon boolean Whether to render only the chevron icon instead of the text label. #}
{% props 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.
Prop Type Default
active 
boolean false
Block Description
content The page number or navigation icon.

<twig:Pagination:Next>

Prop Type Default
asIcon 
boolean false

<twig:Pagination:Previous>

Prop Type Default
asIcon 
boolean false