---
title: Update Storefront to Bootstrap 5
issue: NEXT-15229
author: Tobias Berge
author_email: [email protected]
author_github: @tobiasberge
---
- Added additional npm dependency
bootstrap5
with version5.1.3
- Added npm dependency
@popperjs/core
with version2.10.1
- Added new block
layout_head_javascript_jquery
inResources/views/storefront/layout/meta.html.twig
- Added new block
base_script_jquery
inResources/views/storefront/base.html.twig
- Added global twig variables in
\Shopware\Storefront\Framework\Twig\TemplateDataExtension::getGlobals
- Added variable
dataBsToggleAttr
to replacedata-toggle
withdata-bs-toggle
- Added variable
dataBsDismissAttr
to replacedata-dismiss
withdata-bs-dismiss
- Added variable
dataBsTargetAttr
to replacedata-target
withdata-bs-target
- Added variable
dataBsOffsetAttr
to replacedata-offset
withdata-bs-offset
- Added variable
formSelectClass
to replacecustom-select
withform-select
- Added variable
gridNoGuttersClass
to replaceno-gutters
withg-0
- Added variable
formCheckboxWrapperClass
to replacecustom-control custom-checkbox
withform-check
- Added variable
formRadioWrapperClass
to replacecustom-control custom-radio
withform-check
- Added variable
formCheckInputClass
to replacecustom-control-input
withform-check-input
- Added variable
formCheckLabelClass
to replacecustom-control-label
withform-check-label
- Added variable
formRowClass
to replaceform-row
withrow g-2
- Added variable
modalCloseBtnClass
to replacemodal-close
with'btn-close
- Added variable
visuallyHiddenClass
to replacesr-only
withvisually-hidden
- Added variable
floatStartClass
to replacefloat-left
withfloat-start
- Added variable
floatEndClass
to replacefloat-right
withfloat-end
- Added variable
bgClass
to replacebadge
withbg
- Added variable
- Deprecated Bootstrap class
btn-block
in the following Twig templatesResources/views/storefront/component/checkout/offcanvas-cart.html.twig
Resources/views/storefront/component/listing/filter/filter-multi-select.html.twig
Resources/views/storefront/component/listing/filter/filter-range.html.twig
Resources/views/storefront/component/product/card/action.html.twig
Resources/views/storefront/component/product/card/action.html.twig
Resources/views/storefront/page/checkout/cart/index.html.twig
Resources/views/storefront/page/checkout/confirm/index.html.twig
Resources/views/storefront/page/product-detail/buy-widget-form.html.twig
- Deprecated wrapper element
input-group-append
in the following Twig templates:Resources/views/storefront/layout/header/search.html.twig
Resources/views/storefront/page/checkout/cart/index.html.twig
Resources/views/storefront/component/checkout/offcanvas-cart.html.twig
- Added new breakpoint
xxl
to\Shopware\Storefront\Theme\ThemeConfigValueAccessor::getThemeConfig
- Added new breakpoint
xxl
to twig variablebreakpoint
inResources/views/storefront/base.html.twig
- Added new breakpoint
xxl
to twig variablegallerySliderOptions
inResources/views/storefront/element/cms-element-image-gallery.html.twig
- Added new static
isXXL
inviewport-detection.helper.js
- Added new event dispatch with
Viewport/isXXL
inviewport-detection.helper.js
- Added new breakpoint
xxl
to defaultoptions
ofbase-slider.plugin.js
- Added new breakpoint
xxl
to defaultoptions
ofgallery-slider.plugin.js
- Deprecated all internal jQuery usages in JavaScript plugins, utils and other classes
address-editor.plugin.js
collapse-checkout-confirm-methods.plugin.js
collapse-footer-columns.plugin.js
cross-selling.plugin.js
- Deprecated default option
tabSelector
with valuea[data-toggle="tab"]
- Deprecated default option
fading.plugin.js
zoom-modal.plugin.js
element-loading-indicator.util.js
- Added new const
VISUALLY_HIDDEN_CLASS
- Added new const
loading-indicator.util.js
- Added new const
VISUALLY_HIDDEN_CLASS
- Added new const
ajax-modal-extension.util.js
- Added new const
MODAL_TRIGGER_DATA_ATTRIBUTE
- Added new const
pseudo-modal.util.js
- Added new default SCSS variable overwrite
$link-decoration: none !default;
inResources/app/storefront/src/scss/skin/shopware/abstract/variables/_bootstrap.scss
- Added new default SCSS variable overwrite
$link-hover-decoration: underline !default;
inResources/app/storefront/src/scss/skin/shopware/abstract/variables/_bootstrap.scss
- Deprecated CSS class
.modal-close
inResources/app/storefront/src/scss/component/_zoom-modal.scss
- Deprecated CSS class
.input-group-append
inResources/app/storefront/src/scss/skin/shopware/layout/_header.scss
- Deprecated usages of the next breakpoint for mixin call
media-breakpoint-down()
in the following SCSS files:Resources/app/storefront/src/scss/component/_base-slider.scss
Resources/app/storefront/src/scss/component/_cms-block.scss
Resources/app/storefront/src/scss/component/_cms-element.scss
Resources/app/storefront/src/scss/component/_cms-form-confirmation.scss
Resources/app/storefront/src/scss/component/_cms-sections.scss
Resources/app/storefront/src/scss/component/_filter-panel.scss
Resources/app/storefront/src/scss/component/_gallery-slider.scss
Resources/app/storefront/src/scss/layout/_offcanvas-cart.scss
Resources/app/storefront/src/scss/page/account/_account.scss
Resources/app/storefront/src/scss/page/account/_edit-order.scss
Resources/app/storefront/src/scss/page/account/_order.scss
Resources/app/storefront/src/scss/page/account/_order-detail.scss
Resources/app/storefront/src/scss/page/wishlist/_wishlist.scss
Resources/app/storefront/src/scss/skin/shopware/page/account/_order.scss
Resources/app/storefront/src/scss/skin/shopware/page/account/_order-detail.scss
Resources/app/storefront/src/scss/skin/shopware/page/checkout/_cart.scss
Resources/app/storefront/src/scss/skin/shopware/page/product-detail/_cross-selling.scss
Resources/app/storefront/src/scss/skin/shopware/page/product-detail/_product-detail.scss
Resources/app/storefront/src/scss/skin/shopware/page/product-detail/_tabs.scss
We want to update the Storefront to Bootstrap v5 in the next major release of Shopware. Because Bootstrap v5 introduces breaking changes when updating from Bootstrap v4, we have implemented the update behind a feature flag. This gives you the possibility to test Bootstrap v5 with your apps or themes before the next major release. The current Bootstrap v4 implementation is still the default. With the next major release Bootstrap v5 will be the default.
The Bootstrap v5 preview should not be used in production environments because it is still under development!
- Dropped jQuery dependency (It can be added manually if needed, see "Still need jQuery?")
- Dropped Internet Explorer 10 and 11
- Dropped Microsoft Edge < 16 (Legacy Edge)
- Dropped Firefox < 60
- Dropped Safari < 12
- Dropped iOS Safari < 12
- Dropped Chrome < 60
You can find a full migration guide on the official Bootstrap website: Migrating to v5
- Activate the next major feature flag
V6_5_0_0
in your .env or .psh.override.yaml - Re-build the storefront using
psh.phar storefront:build
- During the build process webpack will show a warning that Bootstrap v5 is being used
- If the Bootstrap v5 resources are not build, please try running
bin/console feature:dump
and try again
Because of the breaking changes inside Bootstrap v5 you will find several places with backward-compatibility code in the Shopware platform. This code is being used to already provide the Bootstrap v5 implementation while keeping the Bootstrap v4 implementation for backward-compatibility. Depending, if you are an app/theme developer or a platform contributor you need to adapt the backward-compatibility for your use case.
- For platform contributors: Use feature flag conditions.
Please use feature flag conditions with flagV6_5_0_0
to migrate to Bootstrap v5 functionality while keeping the Bootstrap v4 implementations for backward-compatibility. - For app/plugin/theme developers: Migrate your code directly to Bootstrap v5 or use feature flag conditions.
- Option A: You can migrate your code directly to Bootstrap v5 by creating a separate git branch and preparing a new release version with the breaking changes.
The major feature flag
V6_5_0_0
can be used to activate Bootstrap v5 during development. - Option B: Depending on you app/plugin/theme it might be more feasible to you to use the major feature flag
V6_5_0_0
to create compatibility to Bootstrap v5. You can use feature flag conditions withV6_5_0_0
inside your app/plugin/theme. The major feature flagV6_5_0_0
will remain inside the shopware platform and will betrue
by default after the release ofv6.5.0.0
- Option A: You can migrate your code directly to Bootstrap v5 by creating a separate git branch and preparing a new release version with the breaking changes.
The major feature flag
You can find some code examples below which will illustrate this. There are always three examples for the same code snippet:
- Bootstrap v4 (Current implementation) - How it looks right now
- Bootstrap v5 with backward-compatibility (for platform contributors or app/plugin/theme developers)
- Bootstrap v5 next major - How it will look after the release of v6.5.0.0 (for app/plugin/theme developers)
Please beware that this is only needed for areas which are effected by braking changes from Bootstrap v5. See: Migrating to v5
<button class="collapsed btn"
data-toggle="collapse"
data-target="#target-selector">
Collapse button
</button>
<a href="#" class="btn btn-block">Default button</a>
2. Bootstrap v5 with backward-compatibility (for platform contributors or app/plugin/theme developers):
Attention: There are a good amount of attributes and classes which have been renamed inside Bootstrap v5.
To avoid having too many {% if %}
conditions in the template we have created global twig variables for attribute renaming.
{# Use global twig variable `dataBsToggleAttr` to toggle between `data-toggle` and `data-bs-toggle`: #}
<button class="collapsed btn"
{{ dataBsToggleAttr }}="collapse"
{{ dataBsTargetAttr }}="#target-selector">
Collapse button
</button>
{# For larger markup changes use regular feature conditions: #}
{# @deprecated tag:v6.5.0 - Bootstrap v5 removes `btn-block` class, use `d-grid` wrapper instead #}
{% if feature('v6.5.0.0') %}
<div class="d-grid">
<a href="#" class="btn">Default button</a>
</div>
{% else %}
<a href="#" class="btn btn-block">Default button</a>
{% endif %}
<button class="collapsed btn"
data-bs-toggle="collapse"
data-bs-target="#target-selector">
Collapse button
</button>
<div class="d-grid">
<a href="#" class="btn">Default button</a>
</div>
.page-link {
line-height: $custom-select-line-height;
}
2. Bootstrap v5 with backward-compatibility (for platform contributors or app/plugin/theme developers):
Attention:
.page-link {
// @deprecated tag:v6.5.0 - Bootstrap v5 renames variable $custom-select-line-height to $form-select-line-height
@if feature('V6_5_0_0') {
line-height: $form-select-line-height;
} @else {
line-height: $custom-select-line-height;
}
}
.page-link {
line-height: $form-select-line-height;
}
$(collapse).collapse('toggle');
2. Bootstrap v5 with backward-compatibility (for platform contributors or app/plugin/theme developers):
// Use feature.helper to check for feature flags.
import Feature from 'src/helper/feature.helper';
/** @deprecated tag:v6.5.0 - Bootstrap v5 uses native HTML elements to init Collapse plugin */
if (Feature.isActive('V6_5_0_0')) {
new bootstrap.Collapse(collapse, {
toggle: true,
});
} else {
$(collapse).collapse('toggle');
}
new bootstrap.Collapse(collapse, {
toggle: true,
});
Since Bootstrap v5 is still behind the next major feature flag V6_5_0_0
it is possible that issues occur.
The following list contains issues that we are aware of. We want to address this issues before the next major version.
- Styling
There might be smaller styling issues here and there. Mostly spacing or slightly wrong colors. - Bootstrap v5 OffCanvas
Bootstrap v5 ships its own OffCanvas component. Shopware is still using its custom OffCanvas at the moment. It is planned to migrate the Shopware OffCanvas to the Bootstrap OffCanvas. - Modifying SCSS $theme-colors
Currently it is not possible to add or remove custom colors to $theme-colors like it is described in the Bootstrap documentation.
Bootstrap v5 introduces breaking changes in HTML, (S)CSS and JavaScript. Below you can find a migration overview of the effected areas in the Shopware platform. Please consider that we cannot provide code migration examples for every possible scenario of a UI-Framework like Bootstrap. You can find a full migration guide on the official Bootstrap website: Migrating to v5
The Update to Bootstrap v5 often contains the renaming of attributes and classes. Those need to be replaced. However, all Twig blocks remain untouched so all template extensions will take effect.
- Replace
data-toggle
withdata-bs-toggle
- Replace
data-dismiss
withdata-bs-dismiss
- Replace
data-target
withdata-bs-target
- Replace
data-offset
withdata-bs-offset
- Replace
custom-select
withform-select
- Replace
custom-file
withform-file
- Replace
custom-range
withform-range
- Replace
no-gutters
withg-0
- Replace
custom-control custom-checkbox
withform-check
- Replace
custom-control custom-switch
withform-check form-switch
- Replace
custom-control custom-radio
withform-check
- Replace
custom-control-input
withform-check-input
- Replace
custom-control-label
withform-check-label
- Replace
form-row
withrow g-2
- Replace
modal-close
withbtn-close
- Replace
sr-only
withvisually-hidden
- Replace
badge-*
withbg-*
- Replace
badge-pill
withrounded-pill
- Replace
close
withbtn-close
- Replace
left-*
andright-*
withstart-*
andend-*
- Replace
float-left
andfloat-right
withfloat-start
andfloat-end
. - Replace
border-left
andborder-right
withborder-start
andborder-end
. - Replace
rounded-left
androunded-right
withrounded-start
androunded-end
. - Replace
ml-*
andmr-*
withms-*
andme-*
. - Replace
pl-*
andpr-*
withps-*
andpe-*
. - Replace
text-left
andtext-right
withtext-start
andtext-end
.
<a href="#" class="btn btn-block">Default button</a>
<div class="d-grid">
<a href="#" class="btn">Default button</a>
</div>
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-append">
<button type="submit" class="btn">Submit</button>
</div>
</div>
<div class="input-group">
<input type="text" class="form-control">
<button type="submit" class="btn">Submit</button>
</div>
Please consider that the classes documented in "HTML/Twig" must also be replaced inside SCSS.
- Replace all mixin usages of
media-breakpoint-down()
with the current breakpoint, instead of the next breakpoint:- Replace
media-breakpoint-down(xs)
withmedia-breakpoint-down(sm)
- Replace
media-breakpoint-down(sm)
withmedia-breakpoint-down(md)
- Replace
media-breakpoint-down(md)
withmedia-breakpoint-down(lg)
- Replace
media-breakpoint-down(lg)
withmedia-breakpoint-down(xl)
- Replace
media-breakpoint-down(xl)
withmedia-breakpoint-down(xxl)
- Replace
- Replace
$custom-select-*
variable with$form-select-*
With the update to Bootstrap v5, the jQuery dependency will be removed from the shopware platform. We strongly recommend migrating jQuery implementations to Vanilla JavaScript.
// Previously Bootstrap plugins were initialized on jQuery elements
const collapse = DomAccess.querySelector('.collapse');
$(collapse).collapse('toggle');
// With Bootstrap v5 the Collapse plugin is instantiated and takes a native HTML element as a parameter
const collapse = DomAccess.querySelector('.collapse');
new bootstrap.Collapse(collapse, {
toggle: true,
});
// Previously Bootstrap events were subscribed using the jQuery `on()` method
const collapse = DomAccess.querySelector('.collapse');
$(collapse).on('show.bs.collapse', this._myMethod.bind(this));
$(collapse).on('hide.bs.collapse', this._myMethod.bind(this));
// With Bootstrap v5 a native event listener is being used
const collapse = DomAccess.querySelector('.collapse');
collapse.addEventListener('show.bs.collapse', this._myMethod.bind(this));
collapse.addEventListener('hide.bs.collapse', this._myMethod.bind(this));
In case you still need jQuery, you can add it to your own app or theme. This is the recommended method for all apps/themes which do not have control over the Shopware environment in which they are running in.
- Extend the file
platform/src/Storefront/Resources/views/storefront/layout/meta.html.twig
. - Use the block
layout_head_javascript_jquery
to add a<script>
tag containing jQuery. Only use this block to add jQuery. - This block is not deprecated and can be used in the long term beyond the next major version of shopware.
- Do not use the
{{ parent() }}
call. This prevents multiple usages of jQuery. Even if multiple other plugins/apps use this method, the jQuery script will only be added once. - Please use jQuery version
3.5.1
(slim minified) to avoid compatibility issues between different plugins/apps. - If you don't want to use a CDN for jQuery, download jQuery from the official website (jQuery Core 3.5.1 - slim minified) and add it to
MyExtension/src/Resources/app/storefront/src/assets/jquery-3.5.1.slim.min.js
- After executing
bin/console asset:install
, you can reference the file using theassset()
function. See also: https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-assets
{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}
{% block layout_head_javascript_jquery %}
<script src="{{ asset('bundles/myextension/assets/jquery-3.5.1.slim.min.js', 'asset') }}"></script>
{% endblock %}
Attention: If you need to test jQuery prior to the next major version, you must use the block base_script_jquery
inside platform/src/Storefront/Resources/views/storefront/base.html.twig
, instead.
The block base_script_jquery
will be moved to layout/meta.html.twig
with the next major version. However, the purpose of the block remains the same:
{% sw_extends '@Storefront/storefront/base.html.twig' %}
{% block base_script_jquery %}
<script src="{{ asset('bundles/myextension/assets/jquery-3.5.1.slim.min.js', 'asset') }}"></script>
{% endblock %}