Sur cette page : découvrez comment ajouter un CSS personnalisé au contenu de votre e-mail dans le Concepteur d’e-mail pour un style avancé, comment conserver la validité de votre CSS et comment résoudre les problèmes liés aux styles qui ne sont pas appliqués.
Lors de la conception de vos e-mails, vous pouvez ajouter votre propre fichier CSS personnalisé directement dans le concepteur d’e-mail Journey Optimizer. Cette fonctionnalité vous permet d’appliquer un style avancé et spécifique, pour une plus grande flexibilité et un meilleur contrôle de l’aspect de votre contenu.
Définir un CSS personnalisé define-custom-css
Pour ajouter du CSS personnalisé au contenu de votre e-mail, procédez comme suit.
-
Vérifiez qu’un contenu est défini dans le concepteur d’e-mail en ajoutant au moins un composant.
-
Sélectionnez Corps dans l’arborescence de navigation à gauche, ou en haut du volet de droite. La section Styles CSS s’affiche à droite.
{width="85%"}
note NOTE La section Styles CSS n’est disponible que lorsque du contenu est déjà présent dans l’éditeur. -
Cliquez sur le bouton Ajouter un fichier CSS personnalisé.
note NOTE Le bouton Ajouter un fichier CSS personnalisé n’est disponible que lorsque Corps est sélectionné. Cependant, vous pouvez appliquer des styles CSS personnalisés à tous les composants de votre contenu. -
Saisissez votre code CSS dans la zone de texte dédiée qui s’affiche. Assurez-vous que le code CSS personnalisé est valide et suit la syntaxe appropriée. En savoir plus
{width="65%"}
note NOTE Lorsque vous utilisez un modèle avec du contenu verrouillé, vous ne pouvez pas ajouter de CSS personnalisé à votre contenu. Le libellé du bouton se transforme en Afficher le CSS personnalisé et tout CSS personnalisé déjà présent dans le contenu est en lecture seule. -
Enregistrez votre CSS personnalisé et vérifiez qu’il s’applique correctement à votre contenu. Si ce n’est pas le cas, consultez la section Dépannage.
{width="85%"}
-
Si vous supprimez tout le contenu, la section disparaît et le CSS personnalisé défini précédemment ne s’applique plus.
-
Ajoutez à nouveau du contenu à l’éditeur pour que la section styles CSS réapparaisse. Le CSS personnalisé s’applique à nouveau.
Vérifier que le CSS est valide use-valid-css
Vous pouvez saisir n’importe quelle chaîne CSS valide dans la zone de texte Ajouter un fichier CSS personnalisé. Si le CSS est correctement formaté, il s’applique immédiatement au contenu.
Vous trouverez ci-dessous des exemples de CSS valide.
| code language-css |
|---|
|
| code language-css |
|---|
|
Si le code CSS saisi n’est pas valide, un message d’erreur s’affiche, indiquant qu’il ne peut pas être enregistré. Vous trouverez ci-dessous des exemples de CSS non valides.
L’utilisation de balises <style> n’est pas acceptée :
| code language-html |
|---|
|
Une syntaxe non valide, comme l’omission des accolades, n’est pas acceptée :
| code language-css |
|---|
|
Implémentation technique implementation
Votre CSS personnalisé est ajouté à la fin de la section <head> dans le cadre d’une balise <style> avec l’attribut data-name="global-custom", comme dans l’exemple ci-dessous. Cela permet de s’assurer que les styles personnalisés sont appliqués globalement au contenu.
| code language-html |
|---|
|
Le CSS personnalisé n’est pas interprété ni validé par le volet Paramètres du concepteur d’e-mail. Il est entièrement indépendant et ne peut être modifié que par l’intermédiaire de l’option Ajouter un fichier CSS personnalisé.
Mécanismes de sécurisation : contenu importé guardrails-imported-content
Si vous souhaitez utiliser un CSS personnalisé avec du contenu importé dans le concepteur d’e-mail, tenez compte des points suivants :
-
Si vous importez du contenu HTML externe, y compris du contenu CSS, sans le convertir, il sera en mode de compatibilité et la section Styles CSS ne sera pas disponible. En savoir plus sur l’import de contenu existant
-
Si vous importez du contenu créé avec le concepteur d’e-mail, y compris le CSS que vous avez appliqué via l’option Ajouter un fichier CSS personnalisé, vous pourrez voir et modifier le CSS appliqué antérieurement à partir de la même option.
Dépannage troubleshooting
Si votre CSS personnalisé n’est pas appliqué, consultez les options ci-dessous.
-
Vérifiez que votre CSS est valide et ne comporte pas d’erreurs de syntaxe (par exemple, des accolades manquantes ou des noms de propriété incorrects). Voici comment procéder
-
Vérifiez que votre CSS est ajouté à la balise
<style>avec l’attributdata-name="global-custom". -
Vérifiez si l’attribut
data-disabledde la balise de styleglobal-customest défini surtrue. Si c’est le cas, le CSS personnalisé n’est pas appliqué.accordion Par exemple : code language-html <style data-name="global-custom" type="text/css" data-disabled="true"> body: { color: red; } </style> -
Vérifiez que votre CSS n’est pas remplacé par d’autres règles CSS, ce qui inclut tout thème appliqué à votre contenu.
-
Utilisez les outils de développement de votre navigateur pour inspecter le contenu et vérifier que votre CSS cible les sélecteurs appropriés.
-
Pensez à ajouter
!importantà vos déclarations pour vous assurer qu’elles sont prioritaires.accordion Par exemple : code language-css .acr-Form { background: red !important; }
-
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: The page explains how to add custom CSS to email content directly within the Journey Optimizer Email Designer for advanced and specific styling, how to make sure the CSS is valid, and what to check when the custom CSS is not applied.
Intents:
- Add custom CSS to email content in the Email Designer by selecting Body, either from the Navigation tree on the left or on top of the right pane, and using the Add Custom CSS button of the CSS styles section.
- Enter valid CSS in the Add custom CSS text area so that it can be saved and applied to the content.
- Find where the custom CSS is added in the HTML of the email content.
- Use custom CSS with content imported into the Email Designer.
- Troubleshoot custom CSS that is not applied to the content.
Glossary:
- CSS styles section (product-specific): The section that displays on the right of the Email Designer when Body is selected, and that contains the Add Custom CSS button.
- global-custom style tag (product-specific): The
<style>tag with thedata-name="global-custom"attribute, at the end of the<head>section of the email content, to which the custom CSS is added. This ensures that the custom styles are applied globally to the content.
Guardrails:
- The CSS styles section is only available when content is already present in the editor.
- The Add custom CSS button is only available when Body is selected. However, custom CSS styles can be applied to all the components inside the content.
- When using a template with locked content, you cannot add custom CSS to the content: the button label changes to View custom CSS and any custom CSS already present in the content is read-only.
- If you remove all content, the CSS styles section disappears and the previously defined custom CSS is no longer applied. When content is added back to the editor, the CSS styles section reappears and the custom CSS is applied again.
- If invalid CSS is entered, an error message is displayed, indicating that the CSS cannot be saved. Properly formatted CSS is immediately applied to the content.
- Users are responsible for the security of their custom CSS. Ensure that your CSS does not introduce vulnerabilities or conflicts with the existing content, and avoid using CSS that could unintentionally break the layout or functionality of the content.
- The custom CSS is not interpreted or validated by the Settings pane of the Email Designer. It is entirely independent and can only be modified through the Add Custom CSS option.
- If you import external HTML content including CSS, unless you convert that content, it is in Compatibility mode, where the CSS styles section is not available.
- If you import content created with the Email Designer including CSS applied through the Add custom CSS option, the CSS previously applied is visible and editable from the same option.
Terminology:
- Canonical name: Add custom CSS — variants: Add Custom CSS
FAQ:
- Why is the CSS styles section not available? The CSS styles section is only available when content is already present in the editor, so add at least one component first. For imported external HTML content that is not converted, the content is in Compatibility mode, where the CSS styles section is not available.
- Can custom CSS style components other than Body? Yes. The Add custom CSS button is only available when Body is selected, but you can apply custom CSS styles to all the components inside your content.
- What happens if I enter invalid CSS? An error message is displayed, indicating that the CSS cannot be saved.
- Can I add custom CSS when using a template with locked content? No. The button label changes to View custom CSS and any custom CSS already present in the content is read-only.
- Where is the custom CSS added in the email HTML? It is added to the end of the
<head>section as part of a<style>tag with thedata-name="global-custom"attribute. - What happens to the custom CSS if I remove all content? The CSS styles section disappears and the previously defined custom CSS is no longer applied. Adding content back makes the section reappear, and the custom CSS is applied again.
Troubleshooting:
-
Custom CSS is not applied: The page lists these checks:
- Ensure that your CSS is valid and free of syntax errors, such as missing braces or incorrect property names.
- Ensure that your CSS is being added to the
<style>tag with thedata-name="global-custom"attribute. - Check if the
global-customstyle tag has the attributedata-disabledset totrue. If this is the case, the custom CSS is not applied. - Ensure that your CSS is not overridden by other CSS rules, including any theme applied to your content. Use your browser developer tools to inspect the content and verify that your CSS is targeting the correct selectors, and consider adding
!importantto your declarations to ensure they take precedence.
Examples:
- Valid custom CSS for the Email Designer:
.acr-Form .spectrum-FieldLabel { width: 20%; }, or the media query@media only screen and (min-width: 600px) { .acr-paragraph-1 { width: 100% !important; } }. - Invalid custom CSS for the Email Designer: CSS wrapped in
<style>tags (for example<style type="text/css"> .acr-Form { width: 100%; } </style>) is not accepted, and invalid syntax such as missing braces (for examplebody { background: red;) is not accepted. - Use of
!importantin custom CSS:.acr-Form { background: red !important; }.
Related pages:
- For the editor in which custom CSS is added: Email Designer
- To add content to the Email Designer before defining custom CSS: component
- For templates in which custom CSS cannot be added: template with locked content
- For importing external HTML content into the Email Designer: Learn more on importing existing content
- For themes that can override custom CSS: theme
Personas:
- marketer: Can add custom CSS in the Email Designer by selecting Body and using the Add Custom CSS button. Can apply custom CSS styles to all the components inside the content. The page states that the CSS styles section is only available when content is already present in the editor. Where: “Define custom CSS”.
Onboarding:
- Level: Intermediate
- First minimal step: Ensure there is some content defined in the Email Designer by adding at least one component.
- Success check: Properly formatted CSS is immediately applied to the content.
- Previous: To have content defined in the Email Designer before adding custom CSS: component