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_attributesnginx
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.
Frequently asked questions
- What does the rewrite_style_attributes filter do?
rewrite_style_attributesapplies CSS rewriting (minification, URL rewriting) to inlinestyle=""attributes on HTML elements.rewrite_style_attributes_with_url(Core filter) does the same but only when the style value contains aurl()reference.- Is rewrite_style_attributes enabled by default?
- No.
rewrite_style_attributesis not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name withEnableFilters. - How do I enable rewrite_style_attributes on Apache and nginx?
- Add
ModPagespeedEnableFilters rewrite_style_attributeson Apache orpagespeed EnableFilters rewrite_style_attributes;on nginx. On IIS, addpagespeed EnableFilters rewrite_style_attributesto pagespeed.config.
Related filters
- rewrite_style_attributes_with_url — Rewrite style attributes with url()
- combine_css — Combine CSS
- compute_critical_css — Compute critical CSS
- extend_cache_css — Extend cache for CSS
- fallback_rewrite_css_urls — Fallback CSS URL rewriting
- flatten_css_imports — Flatten CSS @imports
- inline_css — Inline CSS
- inline_google_font_css — Inline Google Fonts CSS
This page is drawn from the rewrite_style_attributes entry on CSS filters. Every filter in one table: PageSpeed filters.