Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!important should be preserved in inline styles #1260

Open
seb303 opened this issue May 23, 2024 · 3 comments
Open

!important should be preserved in inline styles #1260

seb303 opened this issue May 23, 2024 · 3 comments
Milestone

Comments

@seb303
Copy link

seb303 commented May 23, 2024

Sometimes it is necessary to have inline styles include !important.
For example to remove link underlining in Windows 10 Mail.

However, it seems that Emogrifier drops the !important when inlining the styles. I understand this may be necessary for pseudo-class overrides to work, so it's probably a good default behaviour. But could there be an option added to allow it to be preserved?

@seb303 seb303 changed the title !important should be included inline styles !important should be preserved in inline styles May 23, 2024
@JakeQZ JakeQZ added this to the 8.0.0 milestone May 24, 2024
@JakeQZ
Copy link
Contributor

JakeQZ commented May 24, 2024

I see this could be a useful option.

The !important is removed from inline styles because it is assumed all other rules have been applied inline, and therefore it is unncessariy, and could impact any additional CSS rules - it is impossible to override !important in an inline style.

Pseudo-class (and @media) rules currently don't work as well as they could - we are not adding !important so they are not overriding inline styles when perhaps they should. That is beyond the scope of this.

Would you be willing to create a PR for the option you propose, including tests?

@JakeQZ
Copy link
Contributor

JakeQZ commented May 24, 2024

That said, if Windows 10 Mail uses additional CSS with !important, could you not supply some additional CSS to beat it, with higher specificity and also !important, or is it junking any CSS you provide?

(Windows Mail and Microsoft Outlook I know are terrible, but telling people not to use them is not an option.)

@seb303
Copy link
Author

seb303 commented May 24, 2024

Hi @JakeQZ

I'm not sure I have the experience (or time at the moment) to create a PR & tests, sorry.

Regarding overriding the CSS in another way: I guess we could add back another <style> block after the HTML has been inlined, and put the !important style there. But in general we've reluctant to rely on mail clients honouring <style> blocks. It's much safer to inline everything if possible. I didn't test this with Outlook / Windows 10 Mail yet, but I will give it a try as a workaround for now.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants