Skip to main content

filter · CSS filters

Rewrite style attributes (rewrite_style_attributes)

Category:
CSS
CoreFilters:
No
OptimizeForBandwidth:
No
Risk:
Generally safe

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.

When to use it

  • Not in CoreFilters: it runs only when you enable it by name.
  • Risk rating on these docs: Generally safe.

Risks

The CSS filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters rewrite_style_attributes turns it off for the scope you set it in.

Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

Apache

ModPagespeedEnableFilters rewrite_style_attributes

nginx

pagespeed EnableFilters rewrite_style_attributes;

IIS (pagespeed.config)

pagespeed EnableFilters rewrite_style_attributes
# 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;

Scoping, ForbidFilters and the thresholds filters read: Choosing filters .

Live example

Applies CSS rewriting to inline style="" attributes.

This filter changes how the page is structured or delivered, not its size, so the example shows a source diff rather than a byte or request reduction.

See the before and after, with the source diff →

Frequently asked questions

What does the rewrite_style_attributes filter do?
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.
Is rewrite_style_attributes enabled by default?
No. rewrite_style_attributes is not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name with EnableFilters.
How do I enable rewrite_style_attributes on Apache and nginx?
Add ModPagespeedEnableFilters rewrite_style_attributes on Apache or pagespeed EnableFilters rewrite_style_attributes; on nginx. On IIS, add pagespeed EnableFilters rewrite_style_attributes to pagespeed.config.

This page is drawn from the rewrite_style_attributes entry on CSS filters. Every filter in one table: PageSpeed filters.

Search