I am getting this error in Magento 2.3. Error occurs with every email sent. enter image description here

CSS inlining error: DOMXPath::query(): Invalid expression in selector >> .fotorama__wrap:not(.fotorama__wrap--toggle-arrows) .fotorama__fullscreen-icon << in /var/www/html/magento2/vendor/pelago/emogrifier/src/Emogrifier.php on line 502

I have tried this method:

adding this file in app/design/frontend/VendorTheme/default/web/css/email.less

@import 'source/lib/email/stand/_lib.less'; // Global lib
@import 'source/lib/email/stand/variables/_email.less'; // Global email variables

I have also tried adding

"pelago/emogrifier": "1.0.0 as 0.1.1" in composer.json
  • what is your php version ? Commented May 2, 2019 at 13:48
  • just downgrade the php version 7.3 to 7.2 every thing is working fine Commented May 3, 2019 at 6:22

4 Answers 4


I have got same error and solved as

Just copy these files:




and removed this line from both files '@import 'source/_theme.less'.

Cause by doing this we are separating theme css and email css.

Last run the following commands:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
  • this solution not working so please help me @Rohit Kaushik Commented Dec 30, 2019 at 6:08
  • have you removed _theme.less from both files? /vendor/magento/theme-frontend-blank/web/css/email.less /vendor/magento/theme-frontend-blank/web/css/email-inline.less Commented Jan 3, 2020 at 8:08

Please do not use in your css code selectors with :not(), especially if after another selector follows to ':not' .This is necessary to aviod Еmogrifier errrors

  • I had this &:not(:first-child) { in less and got this error too Invalid expression in selector >> .email-items tbody dl dt:not(:first-child) . Not sure if there is any other way to write same css. Commented Apr 7, 2021 at 6:08
  • 1
    just write styles for all elements '.email-items tbody dl dt' and then write styles for element '.email-items tbody dl dt:first-child' separately. it would be better Commented Apr 8, 2021 at 7:18

I've managed to fix the issue, is not the best practice, but it works.

Go to Marketing > Email Templates and create a new template. Click on Load template and load Magento_Email > Header.

In the Template Content field remove this line:

{{inlinecss file="css/email-inline.css"}}

A better solution would be to fix the issue in the file above.


Another solution:

My PHP version: 7.2.32

composer require pelago/emogrifier:2.0.0

It was not working with pelago/emogrifier:2.2.0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.