Skip to main content
ModPageSpeed 2.0 and mod_pagespeed 1.1 — Coming Soon

CSS Filters

Configure CSS optimization filters in mod_pagespeed 1.1. Minification, combining, inlining, critical CSS extraction, and CSS restructuring.

Overview

mod_pagespeed 1.1 includes filters for CSS minification, combining, inlining, import flattening, and critical CSS extraction. Several CSS filters are CoreFilters and run by default. The remaining filters can be enabled individually or through OptimizeForBandwidth mode.

IIS syntax

On IIS, use the same filter names with the pagespeed prefix in pagespeed.config (no semicolons):

pagespeed EnableFilters rewrite_css,combine_css
pagespeed CssInlineMaxBytes 4096

See IIS Configuration for the full file format reference.

Quick reference

FilterCoreOFBDescriptionSafe
rewrite_cssYesYesMinifies CSS and rewrites embedded URLsGenerally safe
fallback_rewrite_css_urlsYesNoRewrites URLs in unparseable CSSGenerally safe
rewrite_style_attributesNoNoRewrites inline style attributesGenerally safe
rewrite_style_attributes_with_urlYesNoRewrites inline style attributes containing url()Generally safe
combine_cssYesNoCombines multiple CSS files into oneGenerally safe
flatten_css_importsYesNoInlines @import rulesGenerally safe
inline_cssYesNoInlines small external CSS into HTMLGenerally safe
inline_import_to_linkYesNoConverts @import in <style> to <link>Generally safe
inline_google_font_cssNoNoInlines Google Fonts CSSGenerally safe
outline_cssNoNoExternalizes large inline CSSExperimental
prioritize_critical_cssNoNoInlines above-the-fold CSS, defers the restTest first
move_css_above_scriptsNoNoMoves CSS <link> above <script> elementsGenerally safe
move_css_to_headNoNoMoves CSS <link> elements into <head>Generally safe

Filter details

rewrite_css {#rewrite_css}

Core filter. Minifies CSS by removing whitespace, comments, and shortening property values. Also rewrites embedded image URLs so they go through mod_pagespeed’s image optimization pipeline. In OptimizeForBandwidth mode, minifies CSS in-place without changing the URL.

Enable:

# Apache
ModPagespeedEnableFilters rewrite_css
# Nginx
pagespeed EnableFilters rewrite_css;

fallback_rewrite_css_urls {#fallback_rewrite_css_urls}

Core filter. Rewrites resource URLs embedded in CSS files even when CSS parsing fails. Acts as a safety net for non-standard CSS that the full parser cannot handle.

Enable:

# Apache
ModPagespeedEnableFilters fallback_rewrite_css_urls
# Nginx
pagespeed EnableFilters fallback_rewrite_css_urls;

rewrite_style_attributes / rewrite_style_attributes_with_url {#rewrite_style_attributes}

rewrite_style_attributes applies CSS rewriting (minification, URL rewriting) to inline style="" attributes on HTML elements. rewrite_style_attributes_with_url (Core filter) does the same but only when the style value contains a url() reference.

Enable:

# Apache
ModPagespeedEnableFilters rewrite_style_attributes
# or, for URL-only (enabled by default as a CoreFilter):
ModPagespeedEnableFilters rewrite_style_attributes_with_url
# Nginx
pagespeed EnableFilters rewrite_style_attributes;
# or, for URL-only (enabled by default as a CoreFilter):
pagespeed EnableFilters rewrite_style_attributes_with_url;

combine_css {#combine_css}

Core filter. Combines multiple <link rel="stylesheet"> elements into a single CSS file, reducing HTTP requests. Each combined file groups stylesheets that appear consecutively in the HTML. A <script> tag or other non-CSS element between two <link> tags breaks the combination boundary.

Enable:

# Apache
ModPagespeedEnableFilters combine_css
# Nginx
pagespeed EnableFilters combine_css;

flatten_css_imports {#flatten_css_imports}

Core filter. Replaces CSS @import rules with the contents of the imported file. Eliminates round trips caused by import chains. The CssFlattenMaxBytes parameter (default: 102400) limits the size of the resulting flattened CSS.

Enable:

# Apache
ModPagespeedEnableFilters flatten_css_imports
# Nginx
pagespeed EnableFilters flatten_css_imports;

inline_css {#inline_css}

Core filter. Inlines small external CSS files directly into the HTML as <style> blocks. The CssInlineMaxBytes parameter (default: 2048) controls the size threshold.

Enable:

# Apache
ModPagespeedEnableFilters inline_css
# Nginx
pagespeed EnableFilters inline_css;

Core filter. Converts <style>@import url(...);</style> to <link rel="stylesheet">, enabling other CSS filters (combining, minification) to process the imported stylesheet.

Enable:

# Apache
ModPagespeedEnableFilters inline_import_to_link
# Nginx
pagespeed EnableFilters inline_import_to_link;

inline_google_font_css {#inline_google_font_css}

Not a core filter. Fetches the CSS from the Google Fonts API and inlines it directly into the HTML, eliminating one round trip. Requires HTTPS fetching to be enabled. GDPR considerations apply in the EU: inlining the CSS avoids the browser contacting Google Fonts servers directly, which can help with compliance.

Enable:

# Apache
ModPagespeedEnableFilters inline_google_font_css
# Nginx
pagespeed EnableFilters inline_google_font_css;

outline_css {#outline_css}

Experimental. The inverse of inline_css: externalizes large inline <style> blocks into separate CSS files that can be cached independently. Rarely useful in practice. The CssOutlineMinBytes parameter (default: 3000) sets the minimum inline CSS size to externalize.

Enable:

# Apache
ModPagespeedEnableFilters outline_css
# Nginx
pagespeed EnableFilters outline_css;

prioritize_critical_css {#prioritize_critical_css}

Not a core filter. Test before deploying. Identifies CSS rules needed to render above-the-fold content, inlines those rules in the <head>, and defers loading the rest. Uses a JavaScript beacon to collect critical CSS data from real user visits. The beacon endpoint must be accessible for data collection to work. Can significantly improve perceived load time but needs testing with your specific page layouts.

Enable:

# Apache
ModPagespeedEnableFilters prioritize_critical_css
# Nginx
pagespeed EnableFilters prioritize_critical_css;

move_css_above_scripts {#move_css_above_scripts}

Not a core filter. Moves <link rel="stylesheet"> elements above <script> elements in the HTML to prevent CSS-blocking-JS render delays. Generally safe for most sites.

Enable:

# Apache
ModPagespeedEnableFilters move_css_above_scripts
# Nginx
pagespeed EnableFilters move_css_above_scripts;

move_css_to_head {#move_css_to_head}

Not a core filter. Moves <link rel="stylesheet"> elements from the <body> into <head> for earlier browser discovery and faster rendering. Generally safe for most sites.

Enable:

# Apache
ModPagespeedEnableFilters move_css_to_head
# Nginx
pagespeed EnableFilters move_css_to_head;

Tuning parameters

ParameterDefaultDescription
CssInlineMaxBytes2048Max CSS file size (bytes) to inline into HTML
CssFlattenMaxBytes102400Max size (bytes) of flattened CSS after resolving @import
CssOutlineMinBytes3000Min inline CSS size (bytes) to externalize
CssImageInlineMaxBytes0Max image size (bytes) to data-URI inline within CSS (0 = disabled)

Apache syntax:

ModPagespeedCssInlineMaxBytes 4096
ModPagespeedCssFlattenMaxBytes 204800
ModPagespeedCssOutlineMinBytes 5000
ModPagespeedCssImageInlineMaxBytes 2048

Nginx syntax:

pagespeed CssInlineMaxBytes 4096;
pagespeed CssFlattenMaxBytes 204800;
pagespeed CssOutlineMinBytes 5000;
pagespeed CssImageInlineMaxBytes 2048;

See also