The Shopware HTML sanitizer checks HTML code you enter in the administration and removes everything that is not explicitly allowed. Shopware introduced it with version 6.5. If parts of your code are missing after saving, the sanitizer is almost always the reason.
What the sanitizer does
The sanitizer works with allow lists. Every tag and every attribute that is not on the list of the respective field is removed. The text inside a removed tag usually stays.
It applies in two places:
- In the code editor of the administration: As soon as you leave the code view of a text field, the editor replaces your code with the cleaned version. A note below the editor tells you when something was removed.
- On saving: Fields such as the product description or the category description are checked again on the server.
What is allowed
Shopware groups allowed tags and attributes into sets. The details on this page have been checked against Shopware 6.7.15, older versions may differ. By default there are these sets for content:
| Set | Allowed |
|---|---|
basic |
Text and structure, for example a, p, div, span, h1 to h6, lists, tables, img, blockquote, pre. Plus attributes such as class, id, style, href, target, title, src, alt, width and height |
media |
img with src and alt |
HTML5 |
For example section, article, header, footer, nav, figure, figcaption, details, summary, video, audio, source and svg |
bootstrap |
For a and span the attributes role, tabindex, selected aria- attributes (for example aria-label, aria-expanded, aria-controls, aria-hidden) and the Bootstrap attributes data-bs-toggle, data-bs-target, data-bs-dismiss, data-bs-slide, data-bs-slide-to, data-bs-parent, data-bs-config, data-bs-content and data-bs-spy |
snippet |
For a the attributes data-url, data-ajax-modal and data-prev-url |
Which sets apply depends on the field:
| Field | Sets |
|---|---|
| Text element in Shopping Experiences | basic, media, HTML5 |
| Product description | basic, media, HTML5 |
| Snippets | basic, media, HTML5, bootstrap, snippet |
Teaser description of the product (descriptionTeaser) |
no HTML |
| Fields without their own assignment, for example the category description | basic |
What is typically removed
<script>,<style>,<iframe>,<form>and<button>are not part of any set that is assigned to a content field.- Event attributes such as
onclickoronloadare not allowed anywhere. data-attributes are only kept in snippets, and only the ones listed in the setsbootstrapandsnippetonaandspan.video,audioandsvgare only kept in fields with theHTML5set, so not in the category description.
ThemeWare® tip: Design content with CSS classes instead of embedded code. The class attribute is allowed in every field that accepts HTML, and you can find ready-made examples with allowed tags in the article Designing Shopping Experiences with Bootstrap HTML code.
Code is removed, what now?
- Check in the tables above whether the tag and the attribute are allowed in the respective field.
- Replace elements that are not allowed with allowed ones. A link with a button class (
<a class="btn btn-primary">), for example, replaces a<button>. - Move styles to the custom CSS of your theme and only set the class in the content: Individual customizations by means of CSS
- Custom JavaScript does not belong in a content field. This tutorial shows how to embed it: Embed custom JavaScript code
- If you permanently need a tag that Shopware does not allow, the sanitizer can be extended. This requires access to the files of your shop.
Adjusting the sanitizer
The settings are part of the Shopware configuration under shopware.html_sanitizer. Your own values belong in the file config/packages/shopware.yaml of your shop. This is the default assignment of the fields:
shopware:
html_sanitizer:
enabled: true
fields:
- name: product_translation.description
sets: ["basic", "media", "HTML5"]
- name: product_translation.descriptionTeaser
sets: []
- name: app_cms_block.template
sets: ["basic", "media", "tidy", "HTML5"]
- name: snippet.value
sets: ["basic", "media", "bootstrap", "snippet", "HTML5"]
Under sets you create your own sets with tags and attributes, under fields you assign them to a field. The exact structure is described in the Shopware documentation linked at the end of this page.
Important: With enabled: false you switch off the cleaning on the server. We advise against it, because the server then no longer checks HTML code. The adjustment is a change to the system and should be made by your agency or developer. In the Shopware Cloud you have no access to this file.