A few utility functions which may help when working with CSS stylesheets.



Retrieve all url(urlstring) values (in e.g. cssutils.css.CSSImportRule or cssutils.css.CSSValue objects of given sheet.

Parameters:sheetcssutils.css.CSSStyleSheet object whose URLs are yielded

This function is a generator. The generated URL values exclude url( and ) and surrounding single or double quotes.


cssutils.replaceUrls(sheetOrStyle, replacer, ignoreImportRules=False)

Replace all URLs in cssutils.css.CSSImportRule or cssutils.css.CSSValue objects of given sheetOrStyle.

  • sheetOrStyle – a cssutils.css.CSSStyleSheet or a cssutils.css.CSSStyleDeclaration which is changed in place
  • replacer – a function which is called with a single argument url which is the current value of each url() excluding url(, ) and surrounding (single or double) quotes.
  • ignoreImportRules – if True does not call replacer with URLs from @import rules.


cssutils.resolveImports(sheet, target=None)

Recurcively combine all rules in given sheet into a target sheet. @import rules which use media information are tried to be wrapped into @media rules so keeping the media information. This may not work in all instances (if e.g. an @import rule itself contains an @import rule with different media infos or if it contains rules which may not be used inside an @media block like @namespace rules.). In these cases the @import rule is kept as in the original sheet and a WARNING is issued.


given target or a new cssutils.css.CSSStyleSheet object

Table Of Contents

Previous topic

parsing CSS

Next topic

extra settings

This Page