You can style HTML email sent to Gmail using inline style attributes
on HTML elements and <style> blocks inside the <head> element. Unless noted
otherwise, the CSS sanitization rules in this document apply to Google Accounts
in Gmail on the web and in the Gmail mobile apps
for Android and iOS. Gmail supports a subset of CSS selectors,
properties, and media queries, and removes or modifies unsupported CSS rules and
values from the email during sanitization.
For complete lists of supported CSS properties and media queries, see Supported CSS properties and Supported media queries.
This document applies to standard HTML emails. If you're building dynamic emails with AMP for Gmail, see AMP for Email supported CSS.
Style blocks and inline styles
When you use <style> blocks in HTML email, follow these requirements so
Gmail doesn't remove your styles:
- Place
<style>blocks in<head>: Gmail extracts<style>blocks only from the<head>element and removes<style>blocks placed inside the<body>element. - Stay within the 16,384-character limit: The combined content of all
<style>blocks can't exceed 16,384 characters. If a<style>block causes the total to exceed this limit, Gmail discards that entire<style>block and any subsequent<style>blocks. - Use valid CSS syntax: If a
<style>block contains a CSS syntax error, Gmail discards the entire<style>block. - Don't use external stylesheets or font imports: Gmail
removes
<link>elements,@importrules, and@font-facerules. - Send as a raw MIME HTML message: Send HTML emails that use
<style>blocks as raw MIMEtext/htmlmessages, such as over SMTP or with the Gmail API. For details, see Create and send email messages. Pasting or injecting HTML into the Gmail compose window removes<head>and<style>blocks. When a recipient replies to or forwards a message, Gmail also removes<head>and<style>blocks from the quoted or forwarded message and preserves supported inlinestyleattributes. - Inline critical styles for clipped messages: When a recipient prints an
email or opens the entire message, Gmail omits
<style>blocks and applies only inlinestyleattributes. Keep HTML emails compact to avoid clipping, and use inlinestyleattributes for essential layout and text styles.
CSS selectors
You can use element, class, and ID selectors, along with standard combinators, to apply styles. Gmail enforces the following selector rules:
- Pseudo-classes and pseudo-elements: Gmail supports only
the
:hoverpseudo-class (on web and Android; Gmail removes it on iOS) and removes all other pseudo-classes and pseudo-elements. - Attribute selectors: Gmail supports only the
[class~="value"]attribute selector and removes all other attribute selectors. To keepvalueon HTML elements, you must also reference.valueas a class selector in<style>. - Invalid selector removal: If a selector uses an unsupported CSS3
pseudo-class, pseudo-element, or attribute selector (such as
:focus,::before, or[href]), Gmail removes that selector. If no valid selectors remain, Gmail removes the entire rule. Newer selector syntax such as:is(),:where(),:not(.a, .b), or[class~="value" i]fails CSS parsing and discards the entire<style>block. - Class and ID rewriting: Gmail prefixes
classandidvalues with a message-specific identifier to isolate email styles. Gmail removes class names on HTML elements that don't match a.classselector in a<style>block.
Selector example
The following code sample demonstrates how to use selectors:
<html>
<head>
<style>
.colored {
color: blue;
}
#body {
font-size: 14px;
}
</style>
</head>
<body>
<div id='body'>
<p>Hi Pierce,</p>
<p class='colored'>This text is blue.</p>
<p>Jerry</p>
</div>
</body>
</html>
CSS media queries
You can use CSS @media queries to adjust email styling for the user's device.
Gmail supports queries against screen
width, device width, orientation, and resolution, with the following
limitations:
- Supported media types: Gmail supports only the lowercase
allandscreenmedia types. - Supported logical keywords: Gmail supports only the
lowercase
andandonlykeywords, and doesn't supportnot. - Feature expression syntax: Each media feature expression must include a
lowercase feature name, a colon, and a value, such as
(min-width: 500px). Range comparison operators (such as(width >= 500px)) fail CSS parsing and discard the entire<style>block. - Unsupported query removal: Gmail removes any media query
that uses an unsupported media type, keyword, feature (such as
prefers-color-scheme), or boolean feature without a value (such as(orientation)). - Android width rewriting: On Android, Gmail rewrites
width,min-width, andmax-widthin media queries todevice-width,min-device-width, andmax-device-width.
Media query example
The following code sample demonstrates how to use media queries:
<html>
<head>
<style>
.colored {
color: blue;
}
#body {
font-size: 14px;
}
@media screen and (min-width: 500px) {
.colored {
color:red;
}
}
</style>
</head>
<body>
<div id='body'>
<p>Hi Pierce,</p>
<p class='colored'>
This text is blue if the window width is
below 500px and red otherwise.
</p>
<p>Jerry</p>
</div>
</body>
</html>
CSS property limitations
Gmail sanitizes CSS declarations and modifies certain property values to keep email content contained within the message view:
- Unsupported properties: Gmail removes properties not
listed in Supported CSS properties. Common unsupported
properties include
position,top,right,bottom,left,z-index,flex,grid,justify-content,align-items,gap,background-attachment,box-shadow,color-scheme,list-style-image,transform,transition, and CSS custom properties (--*). - Background images: Gmail supports
url()andimage-set()only inbackgroundandbackground-image, using publicly accessiblehttp://orhttps://URLs (through Google's image proxy) orcid:attachment references. Gmail rewritesdata:URLs tourl('')and removes declarations that useurl()in other properties (such aslist-style). If a recipient blocks external images or Gmail flags a message as spam or suspicious, Gmail stripsurl()values until the recipient displays images. Include a fallbackbackground-colorso text remains legible. - Gradients and CSS functions: Gmail supports
linear-gradient(),radial-gradient(),repeating-linear-gradient(),repeating-radial-gradient(), and math functions (calc(),min(),max(),clamp()). Gmail removes declarations that useconic-gradient(),repeating-conic-gradient(),light-dark(),image(),element(), ortype()insideimage-set(). Color functionsrgb(),rgba(),hsl(), andhsla()require comma-separated arguments (such asrgb(255, 0, 0)). Space-separated color or image functions—includingrgb(255 0 0 / 50%),oklch(),oklab(),lab(),lch(),hwb(),color(),color-mix(), andcross-fade()—fail CSS parsing and discard the<style>block orstyleattribute. - Layout and shorthand values: Although Gmail supports
display(such asblock,inline-block,table, andnone), it removes companion flexbox and grid properties (flex,grid,justify-content,align-items, andgap). Use HTML<table>elements for multi-column layouts. Forfont-style, Gmail accepts onlynormal,italic,oblique, andinherit(with optional!important) and removes other values. - Negative margins and text indentation: Gmail removes
negative values (or expressions containing
-, such ascalc(100% - 20px)) formargin,margin-top,margin-right,margin-bottom,margin-left, andtext-indent. - Whitespace wrapping: Gmail converts
white-space: pretowhite-space: pre-wrapso long lines wrap within the message view.
Dark theme
Gmail handles dark theme (dark mode) differently across clients and doesn't support custom CSS dark-mode rules:
- No
prefers-color-schemeorcolor-schemeCSS support: Gmail removes@media (prefers-color-scheme: dark)(andlight) queries and thecolor-schemeCSS property during sanitization. - Web and mobile app differences: In the Gmail mobile apps for Android and iOS, dark theme automatically adjusts HTML email colors by darkening light backgrounds and lightening dark text. In Gmail on the web, dark theme styles the Gmail interface while rendering HTML email bodies on a light background by default.
- Opting out of mobile color inversion: To keep an email in light theme
for Google Accounts in the Gmail mobile apps, add
<meta name="color-scheme" content="light only">in<head>. You can also usename="supported-color-schemes", and bothnameandcontentvalues must be lowercase (such ascontent="light only"orcontent="only light").
Supported CSS properties
The following table groups all CSS properties that pass Gmail CSS sanitization, subject to client rendering support and the value restrictions in CSS property limitations. Use the filter box to check whether Gmail supports a specific property:
| Category | Supported properties |
|---|---|
| Background and color |
background, background-blend-mode,
background-clip, background-color,
background-image, background-origin,
background-position, background-repeat,
background-size, color,
isolation, mix-blend-mode,
opacity
|
| Borders and outlines |
border, border-bottom,
border-bottom-color,
border-bottom-left-radius,
border-bottom-right-radius,
border-bottom-style, border-bottom-width,
border-color, border-left,
border-left-color, border-left-style,
border-left-width, border-radius,
border-right, border-right-color,
border-right-style, border-right-width,
border-style, border-top,
border-top-color, border-top-left-radius,
border-top-right-radius, border-top-style,
border-top-width, border-width,
outline, outline-color,
outline-style, outline-width
|
| Box model, sizing, and spacing |
box-sizing, clear, display,
float, height, margin,
margin-bottom, margin-left,
margin-right, margin-top,
max-height, max-width,
min-height, min-width,
overflow, overflow-x,
overflow-y, padding,
padding-bottom, padding-left,
padding-right, padding-top,
width
|
| Typography and fonts |
font, font-family,
font-feature-settings, font-kerning,
font-size, font-size-adjust,
font-stretch, font-style,
font-synthesis, font-variant,
font-variant-alternates,
font-variant-caps,
font-variant-east-asian,
font-variant-ligatures,
font-variant-numeric, font-weight,
letter-spacing, line-height,
quotes
|
| Text layout and decoration |
direction, line-break,
text-align, text-align-last,
text-autospace, text-combine-upright,
text-decoration, text-decoration-color,
text-decoration-line,
text-decoration-skip,
text-decoration-style, text-emphasis,
text-emphasis-color, text-emphasis-style,
text-indent, text-justify,
text-orientation, text-overflow,
text-transform, text-underline-position,
unicode-bidi, vertical-align,
white-space, word-break,
word-spacing, word-wrap,
writing-mode
|
| Tables and lists |
border-collapse, border-spacing,
caption-side, empty-cells,
list-style, list-style-position,
list-style-type, marker-offset,
table-layout
|
| Columns and page breaks |
break-after, break-before,
break-inside, column-count,
column-fill, column-gap,
column-rule, column-rule-color,
column-rule-style, column-rule-width,
column-span, column-width,
columns, page-break-after,
page-break-before, page-break-inside
|
| Images and replaced elements |
image-orientation, image-resolution,
object-fit, object-position
|
| Legacy and speech (aural) |
azimuth, elevation, ime-mode,
layout-flow, layout-grid,
layout-grid-char,
layout-grid-char-spacing,
layout-grid-line, layout-grid-mode,
layout-grid-type, pause,
pause-after, pause-before,
pitch, pitch-range, richness,
speak, speak-header,
speak-numeral, speak-punctuation,
speech-rate, stress,
text-kashida-space, voice-family,
zoom
|
Supported media queries
The following table lists the @media types, features, and logical keywords
that Gmail supports, subject to the rules in
CSS media queries:
| Component | Supported values | Notes |
|---|---|---|
| Media types | all, screen |
Lowercase only; at most one media type per query. |
| Media features |
width, min-width, max-width,
device-width, min-device-width,
max-device-width, orientation,
resolution, min-resolution,
max-resolution
|
Lowercase (feature: value) syntax only. On Android,
Gmail rewrites width,
min-width, and max-width to
device-width equivalents.
|
| Logical keywords | and, only |
Lowercase only; Gmail doesn't support not.
|