email-bugs icon indicating copy to clipboard operation
email-bugs copied to clipboard

Gmail removes <style> tags or style attributes that contains an uppercase !IMPORTANT

Open hteumeuleu opened this issue 8 years ago • 3 comments

Gmail removes any <style> tags or inline style attribute that contains an uppercase !IMPORTANTdeclaration.

The following code…

<html>
<head>
    <style>
        div { background:#2ECC40; }
        p { color:#fff !important; }
    </style>
    <style>
        div { background:#FF4136; }
        p { color:#fff !IMPORTANT; }
    </style>
</head>
<body>
    <p style="color:#fff !important; background:#2ECC40;">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit.
    </p>
    <p style="color:#fff !IMPORTANT; background:#FF4136;">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit.
    </p>
</body>
</html>

…is transformed by Gmail into the following :

<html>
<head>
    <style>
        div { background:#2ECC40; }
        p { color:#fff !important; }
    </style>
</head>
<body>
    <p style="color:#fff !important; background:#2ECC40;">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit.
    </p>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit.
    </p>
</body>
</html>

As per CSS 2 specification, "all CSS syntax is case-insensitive".

This was discovered and reported by Sam Lewis on the Litmus forums.

hteumeuleu avatar Feb 22 '16 21:02 hteumeuleu

This bug is still present in Gmail as of today.

hteumeuleu avatar Jan 30 '18 15:01 hteumeuleu

As noted by @m-j-robbins yesterday, this also happens when using any case other than lowercase. (So !iMpOrTaNt also triggers the <style> tag to be completely removed.)

hteumeuleu avatar Nov 30 '21 13:11 hteumeuleu

Just wanted to look into this further - I looked up the CSS specification on how to 'consume a declaration' and it says:

If the last two non-whitespace-tokens in the declaration’s value are a delim-token with the value "!" followed by an ident-token with a value that is an ASCII case-insensitive match for "important", remove them from the declaration’s value and set the declaration’s important flag to true.

Reading the above !IMPORTANT is valid CSS. In the ASCII case-insensitive spec it states:

A string A is an ASCII case-insensitive match for a string B, if the ASCII lowercase of A is the ASCII lowercase of B.

JayOram avatar Dec 02 '21 11:12 JayOram