Skip to content

[Docs] Explain Icons SVG size #2670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/Icons/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Installation
$ composer require symfony/ux-icons

# To use provided on-demand icon sets, you also need HTTP client:
$ composer require symfony/http-client
$ composer require symfony/http-client

SVG Icons
---------
Expand Down Expand Up @@ -77,6 +77,38 @@ define the HTML attributes added to the ``<svg>`` element:
{{ ux_icon('user-profile', {height: '16px', width: '16px', 'aria-hidden': true}) }}
{# renders <svg height="16" width="16" aria-hidden="true"> ... </svg> #}

Icon Sizes
~~~~~~~~~~

.. note::

``<svg>`` elements will be dynamically sized by the browser.
For icons, we therefore recommend to explicitly set the size.

To align icons naturally with surrounding text and inherit font sizing, use ``em``
units. This works well for buttons, links, or inline text. Defining the height alone
is sufficient—the width will scale proportionally:

.. code-block:: html+twig

{# Twig function #}
{{ ux_icon('user-profile', {style: 'height: 1em;'}) }}

{# HTML syntax #}
<twig:ux:icon name="profile" style="height: 1em;" />

If your project uses a CSS framework like Tailwind or Bootstrap, prefer their
sizing utilities for consistency and theming:

.. code-block:: html+twig

{# Twig function #}
{{ ux_icon('bi:chat', {class: 'size-4'}) }}

{# HTML syntax #}
<twig:ux:icon name="bi:chat" class="size-4" />

To keep your design consistent and easily adjustable, consider defining a :ref:default attribute <icons_default_attributes>. This allows you to control the size of all your icons from a single place.

Icon Sets
~~~~~~~~~
Expand Down Expand Up @@ -328,6 +360,8 @@ HTML Syntax

``symfony/ux-twig-component`` is required to use the HTML syntax.

.. _icons_default_attributes:

Default Attributes
~~~~~~~~~~~~~~~~~~

Expand Down