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

  1. 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']).
  2. 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']).
  3. 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, and whitelist.
  4. 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) { ... }

Return Value

  • Type: String | undefined
  • Description:
    • If no callback is provided and the options.output path is not set, the function returns the purified CSS as a String.
    • If a callback is provided or options.output is set, the function returns undefined.

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);