API Reference
This page provides a detailed reference for the main PurifyCSS function.
purify(content, css, [options], [callback])
This is the core function of the library. It takes content and CSS as input, and returns the purified CSS.
Parameters
-
content- Type:
String|Array<String> - Description: The source content to scan for used CSS selectors. This can be:
- A
Stringcontaining raw content (e.g., HTML, JavaScript code). - An
Arrayof file paths and/or glob patterns that point to your content files (e.g.,['./src/**/*.html', './src/**/*.js']).
- A
- Type:
-
css- Type:
String|Array<String> - Description: The CSS you want to purify. This can be:
- A
Stringof raw CSS code. - An
Arrayof file paths and/or glob patterns that point to your CSS files (e.g.,['./styles/main.css', './styles/vendor/*.css']).
- A
- Type:
-
options(Optional)- Type:
Object - Description: An optional object to configure the behavior of PurifyCSS. See the Usage Guide for a detailed list of all available properties like
minify,output,info,rejected, andwhitelist.
- Type:
-
callback(Optional)- Type:
Function - Description: An optional callback function that will be executed upon completion. The function receives one argument: the purified CSS string.
- Signature:
function(purifiedCss) { ... }
- Type:
Return Value
- Type:
String|undefined - Description:
- If no
callbackis provided and theoptions.outputpath is not set, the function returns the purified CSS as aString. - If a
callbackis provided oroptions.outputis set, the function returnsundefined.
- If no
Function Signatures
PurifyCSS supports multiple argument combinations:
// With options and callback
purify(content, css, options, callback);
// With callback only
purify(content, css, callback);
// With options only (synchronous return or file output)
purify(content, css, options);
// Without options or callback (synchronous return)
purify(content, css);