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
String
containing raw content (e.g., HTML, JavaScript code). - An
Array
of 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
String
of raw CSS code. - An
Array
of 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
callback
is provided and theoptions.output
path is not set, the function returns the purified CSS as aString
. - If a
callback
is provided oroptions.output
is 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);