Skip to content

Icon

Use icon element to style icons anywhere on the page.

Examples

Storefront theme provides predefined stylings for various icons according to props of the icon macro. Those stylings are icon_l, icon_xl, icon_xxl, icon_clickable, icon_filled, icon_no-stroke, icon_link, icon_success and icon_error.

HTML
<svg class="icon icon_l">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-chevron-down"></use>
</svg>

<svg class="icon icon_xl">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-search"></use>
</svg>

<svg class="icon icon_xxl">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-basket"></use>
</svg>

<svg class="icon icon_clickable">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-credit-card"></use>
</svg>

<svg class="icon icon_filled">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-heart"></use>
</svg>

<svg class="icon icon_no-stroke">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-check-circle"></use>
</svg>

<svg class="icon icon_link">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-download"></use>
</svg>

<svg class="icon icon_success">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-message-circle"></use>
</svg>

<svg class="icon icon_error">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-send"></use>
</svg>

Icon tags

The .icon class was designed to be used with <svg> elements. However, you can use them with any element. Eg. <div> or <span>.

Icon sizes

Each icon can have different sizes. We support styles for 3 different size modifiers: l, xl and xxl. To change the icon size, add icon_l, icon_xl or icon_xxl class to your icon.

HTML
<svg class="icon icon_l">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-basket"></use>
</svg>

<svg class="icon icon_xl">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-send"></use>
</svg>

<svg class="icon icon_xxl">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-credit-card"></use>
</svg>

Icon variants

Each icon can have different color scheme according to the chosen variant. We support styles for 3 variants: link, success and error. You can change the variant by adding one of the following classes: icon_link, icon_success, icon_error.

HTML
<svg class="icon icon_link">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-basket"></use>
</svg>

<svg class="icon icon_success">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-send"></use>
</svg>

<svg class="icon icon_error">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-credit-card"></use>
</svg>

Other icon modifiers

We provide additional modifiers to make the usage of the icons simpler. You can modify any icon to be clickable with icon_clickable class, to be filled with icon_filled class or to have no stroke with icon_no-stroke class.

HTML
<svg class="icon icon_clickable">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-basket"></use>
</svg>

<svg class="icon icon_filled">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-send"></use>
</svg>

<svg class="icon icon_no-stroke">
    <use xlink:href="https://example.com/assets/img/icons/symbol-defs.svg#icon-credit-card"></use>
</svg>

Custom icon set

You can replace the default icon set with your own. In the theme settings, go to the Icons section, check Replace default icons with your own and upload an SVG file. Learn how to prepare a file with your custom icon set.

The file is an SVG sprite. Each icon is a <symbol> element, and its id is the icon name:

SVG
<svg xmlns="http://www.w3.org/2000/svg">
    <defs>
        <symbol id="icon-leaf" viewBox="0 0 24 24">
            <path d="..."></path>
        </symbol>
    </defs>
</svg>

Your icon set replaces the default one

Theme modules find icons by name, for example icon-heart or icon-search. An icon whose name is missing from your file will not be displayed. Start from the default set (/assets/img/icons/symbol-defs.svg) and add your own symbols to it.

After you upload the file, the icon macro and the h-icon webcomponent use your icon set by default. You don't need to provide the file path.

Custom icons in your own modules

Use the icon macro in the module template:

Twig
{% from "@macros/icon.twig" import icon %}

{{ icon('icon-leaf', { size: 'l' }) }}

Custom icons in WYSIWYG content

WYSIWYG content is HTML, so you can't use macros in it. Switch the editor to the code view and add the h-icon webcomponent:

HTML
<h-icon icon-name="icon-leaf" size="l"></h-icon>

The h-icon webcomponent always uses the icon set that is currently uploaded. If you upload a new version of the file, you don't need to change the WYSIWYG content.

The default icon styles are designed for outline icons. If your icons are filled shapes, use the filled and noStroke modifiers described above.

LESS

You can modify any icon less variable in your User Less section to change icon styles.

Icon variables

Variables used to style icons.

@iconMSize: 16px;
@iconLSize: 20px;
@iconXlSize: 24px;
@iconXxlSize: 32px;
@iconXxxlSize: 64px;

@iconColor: @globalFontColor;

@iconVariantLinkColor: @linkColorPrimary;

@iconVariantSuccessColor: @primaryColor;

@iconVariantErrorColor: @globalFontColor;

@iconVariantPromoColor: @neutralColors0;
@iconVariantPromoBgColor: @secondaryColor;
@iconVariantPromoPadding: 1;
@iconVariantPromoBorderRadius: 2;

If you want to change icon styles, you can just change the variables. To change default stroke just modify @iconColor variable.

@iconColor: red;

Icon mixins

Those mixins are used to create icons.

.icon-m () {
    width: @iconMSize;
    height: @iconMSize;
}

.icon-l () {
    width: @iconLSize;
    height: @iconLSize;
}

.icon-xl () {
    width: @iconXlSize;
    height: @iconXlSize;
}

.icon-xxl () {
    width: @iconXxlSize;
    height: @iconXxlSize;
}

.icon-xxxl () {
    width: @iconXxxlSize;
    height: @iconXxxlSize;
}

Icon standard styles

Here are standard icon styles.

.icon {
    fill: transparent;
    stroke: @iconColor;

    .icon-m();

    &_l {
        .icon-l();
    }

    &_xl {
        .icon-xl();
    }

    &_xxl {
        .icon-xxl();
    }

    &_xxxl {
        .icon-xxxl();
    }

    &_clickable {
        cursor: pointer;
    }

    &_filled {
        fill: @iconColor;
    }

    &_no-stroke {
        stroke: transparent;
    }

    &_secondary-color {
        stroke: @globalFontColorSecondary;
    }

    &_tertiary-color {
        stroke: @globalFontColorTertiary;
    }

    &_link {
        fill: transparent;
        stroke: @iconVariantLinkColor;
    }

    &_success {
        fill: transparent;
        stroke: @iconVariantSuccessColor;

        &-filled {
            stroke: @neutralColors0;
            background-color: @iconVariantSuccessColor;
            border-radius: 50%;
            vertical-align: middle;
            padding: 0.5rem;
            box-shadow: 0 0 0px 6px @successColors50;
        }
    }

    &_error {
        fill: transparent;
        stroke: @iconVariantErrorColor;

        &-filled {
            stroke: @neutralColors0;
            background-color: @iconVariantErrorColor;
            border-radius: 50%;
            vertical-align: middle;
            padding: 0.5rem;
            box-shadow: 0 0 0px 6px @errorColors50;
        }
    }

    &_promo {
        fill: transparent;
        stroke: @iconVariantPromoColor;
        background-color: @iconVariantPromoBgColor;
        .pixel-to-rem(padding, @iconVariantPromoPadding);
        .pixel-to-rem(border-radius, @iconVariantPromoBorderRadius);
        vertical-align: middle;
    }
}

h-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

Macros reference