CSS support in HTML emails

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, @import rules, and @font-face rules.
  • Send as a raw MIME HTML message: Send HTML emails that use <style> blocks as raw MIME text/html messages, 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 inline style attributes.
  • Inline critical styles for clipped messages: When a recipient prints an email or opens the entire message, Gmail omits <style> blocks and applies only inline style attributes. Keep HTML emails compact to avoid clipping, and use inline style attributes 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 :hover pseudo-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 keep value on HTML elements, you must also reference .value as 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 class and id values with a message-specific identifier to isolate email styles. Gmail removes class names on HTML elements that don't match a .class selector 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 all and screen media types.
  • Supported logical keywords: Gmail supports only the lowercase and and only keywords, and doesn't support not.
  • 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, and max-width in media queries to device-width, min-device-width, and max-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() and image-set() only in background and background-image, using publicly accessible http:// or https:// URLs (through Google's image proxy) or cid: attachment references. Gmail rewrites data: URLs to url('') and removes declarations that use url() in other properties (such as list-style). If a recipient blocks external images or Gmail flags a message as spam or suspicious, Gmail strips url() values until the recipient displays images. Include a fallback background-color so 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 use conic-gradient(), repeating-conic-gradient(), light-dark(), image(), element(), or type() inside image-set(). Color functions rgb(), rgba(), hsl(), and hsla() require comma-separated arguments (such as rgb(255, 0, 0)). Space-separated color or image functions—including rgb(255 0 0 / 50%), oklch(), oklab(), lab(), lch(), hwb(), color(), color-mix(), and cross-fade()—fail CSS parsing and discard the <style> block or style attribute.
  • Layout and shorthand values: Although Gmail supports display (such as block, inline-block, table, and none), it removes companion flexbox and grid properties (flex, grid, justify-content, align-items, and gap). Use HTML <table> elements for multi-column layouts. For font-style, Gmail accepts only normal, italic, oblique, and inherit (with optional !important) and removes other values.
  • Negative margins and text indentation: Gmail removes negative values (or expressions containing -, such as calc(100% - 20px)) for margin, margin-top, margin-right, margin-bottom, margin-left, and text-indent.
  • Whitespace wrapping: Gmail converts white-space: pre to white-space: pre-wrap so 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-scheme or color-scheme CSS support: Gmail removes @media (prefers-color-scheme: dark) (and light) queries and the color-scheme CSS 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 use name="supported-color-schemes", and both name and content values must be lowercase (such as content="light only" or content="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.