scssphp is a compiler for SCSS written in PHP.

SCSS is a CSS preprocessor language that adds many features like variables, mixins, imports, nesting, color manipulation, functions, and control directives.

scssphp is ready for inclusion in any project. It includes a command line tool for running the compiler from a terminal/shell or script.

Installing

You can always download the latest version here: scssphp-v1.8.1.tar.gz

You can also find the latest source online: https://github.com/scssphp/scssphp/

If you use Packagist for installing packages, then you can update your composer.json like so:

{
    "require": {
        "scssphp/scssphp": "^1.8.1"
    }
}

Note: git archives of stable versions no longer include the tests/ folder. To install the unit tests, download the complete package source using composer’s --prefer-source option.

scssphp requires PHP version 5.6 (or above).

Language Reference

For a complete guide to the syntax of SCSS, consult the official documentation.

Note that scssphp is not fully compliant with the Sass specification yet. Sass modules are not implemented yet either.

Command Line Tool

A really basic command line tool is included for integration with scripts. It is called pscss. It reads SCSS from either a named input file or standard in, and returns the CSS to standard out.

Usage: bin/pscss [options] [input-file] [output-file]

Options

If passed the flag -h (or --help), input is ignored and a summary of the command’s usage is returned.

If passed the flag -v (or --version), input is ignored and the current version is returned.

The flag -s (or --style) can be used to set the output style:

$ bin/pscss -s compressed styles.scss

The flag -I (or --load_path) can be used to set import paths for the loader. On Unix/Linux systems, the paths are colon separated. On Windows, they are separated by a semi-colon.

SCSSPHP Library Reference

To use the scssphp library either require scss.inc.php or use your composer generated auto-loader, and then invoke the \ScssPhp\ScssPhp\Compiler class:

require_once "scssphp/scss.inc.php";

use ScssPhp\ScssPhp\Compiler;

$compiler = new Compiler();

echo $compiler->compileString('
  $color: #abc;
  div { color: lighten($color, 20%); }
')->getCss();

The compileString method takes the SCSS source code as a string and an optional path of the input file (to resolve relative imports), and returns a CompilationResult value object containing the CSS and some additional data. If there is an error when compiling, a \ScssPhp\ScssPhp\Exception\SassException is thrown with an appropriate message.

For a more detailed guide, consult the documentation.

Issues

Please submit bug reports and feature requests to the the issue tracker. Pull requests are also welcome.

Any feature request about implementing new language feature will be rejected. They must be submitted to the upstream Sass project instead.

Changelog

For a list of scssphp changes, refer to the changelog.

Fork me on GitHub