PHPackages                             kylekatarnls/stylus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kylekatarnls/stylus

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kylekatarnls/stylus
===================

Stylus preprocessor for PHP (see https://github.com/AustP/Stylus.php, it's an exact fork except the minimum stability)

1.0.8(6y ago)5137.6k↓36.2%11MITPHPPHP &gt;=5.3.0

Since Sep 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/kylekatarnls/Stylus.php)[ Packagist](https://packagist.org/packages/kylekatarnls/stylus)[ RSS](/packages/kylekatarnls-stylus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (12)Used By (1)

Stylus.php
==========

[](#stylusphp)

A Stylus parser for PHP

---

### CSS needs a hero... again

[](#css-needs-a-hero-again)

When I first saw [Stylus](http://learnboost.github.com/stylus/) I thought it was amazing and I implemented it into my nodejs application. When I started my next project, which was a PHP project, I liked Stylus so much that I wanted to implement it into my PHP project as well. Surprisingly, I couldn't find any Stylus parser for PHP. So I did as any developer would do and created my own. And I want to share it.

Current Features
----------------

[](#current-features)

- Omit braces
- Omit colons
- Omit semi-colons
- Custom functions
- Importing other files
- '&amp;' parent reference
- Mixins
- Interpolation
- Variables

Using Stylus.php
----------------

[](#using-stylusphp)

Using Stylus.php is really easy! Just include the following code:

```
require('Stylus.php');

$stylus = new Stylus();
$stylus->setReadDir('read');
$stylus->setWriteDir('write');
$stylus->setImportDir('import'); //if you import a file without setting this, it will import from the read directory
$stylus->parseFiles();
```

And that's all there is to it! Now a quick note about the `parseFiles()` function. It has one parameter called `overwite` which defaults to `false`. It is a flag indicating whether or not you want to overwrite your already parsed Stylus files.

This means that you could include this code on every page and you won't be parsing your Stylus files every time. But make sure that you set `overwrite` to `true` when you are developing or updating your Stylus files so the changes will be reflected in your site.

### Parse a single file or strings

[](#parse-a-single-file-or-strings)

Instead of compiling all the files in the read directory, you can choose exactly what to do using the following syntax.

```
// From string to string
$css = $stylus->fromString("body\n  color black")->toString();

// From string to file
$stylus->fromString("body\n color black")->toFile("out.css");

// From file to string
$css = $stylus->fromFile("in.styl")->toString();

// From file to file
$stylus->fromFile("in.styl")->toFile("out.css");
```

`toFile($file, $overwrite)` takes two parameter, both of them optional.

- `$file`: The filename to write to, if ommited or null it will take the input filename and change `.styl` to `.css`.
- `$overwrite`: Specifies wheter or not to parse and write the file if a file with the same name is found.

Assigning Variables
-------------------

[](#assigning-variables)

Assigning variables is done the same way as in regular Stylus. But you now have the option of adding variables from PHP before parsing the stylus files by calling the `assign` function. Here is an example:

**PHP**

```
$stylus->assign('px_size', '30px');
$stylus->parseFiles();
```

**Stylus**

```
div
  font-size px_size
```

**Yields**

```
div {
    font-size: 30px;
}
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~197 days

Recently: every ~333 days

Total

9

Last Release

2327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/df90c422f521bf26355c3e185a59fe7afb35531af56244dfaec03ee1d0ca6f24?d=identicon)[kylekatarn](/maintainers/kylekatarn)

---

Top Contributors

[![AustP](https://avatars.githubusercontent.com/u/2007045?v=4)](https://github.com/AustP "AustP (23 commits)")[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (13 commits)")[![LinusU](https://avatars.githubusercontent.com/u/189580?v=4)](https://github.com/LinusU "LinusU (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kylekatarnls-stylus/health.svg)

```
[![Health](https://phpackages.com/badges/kylekatarnls-stylus/health.svg)](https://phpackages.com/packages/kylekatarnls-stylus)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
