PHPackages                             devly/css-generator - 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. devly/css-generator

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

devly/css-generator
===================

Generate CSS on the fly using PHP

1.0.0(1y ago)1262MITPHPPHP &gt;=7.4

Since Feb 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/valenjeb/css-generator)[ Packagist](https://packagist.org/packages/devly/css-generator)[ RSS](/packages/devly-css-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

CSS Generator
=============

[](#css-generator)

Generate CSS on the fly using PHP.

Usage
-----

[](#usage)

```
use Devly\CssGenerator\CSS;
$options = [
    'indent' => 4, // Default indent: 4 spaces
    'minify' => false, // Default false
];
$css = CSS::new([], $options);
$css->charset('utf-8');
$css->import('path/to/imported.css');
$css->import('path/to/second-imported.css')
    ->supports('display: block')
    ->media('screen');
$css->selector('body')
    ->fontFamily('Arial, sans-serif')
    ->fontSize('16px')
    ->lineHeight(1.5);
$css->media('screen and (min-width: 768px)')
    ->selector('body')
    ->fontSize('18px')
    ->endMedia();

echo $css->compile();
```

### Output

[](#output)

```
@charset "utf-8";
@import "path/to/imported.css";
@import "path/to/second-imported.css" supports(display: block) screen;

body {
    font-family: Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

@media screen and (min-width: 768px) {
    body {
        font-size: 18px;
    }
}
```

### With minify enabled

[](#with-minify-enabled)

```
@charset "utf-8";@import "path/to/imported.css";@import "path/to/second-imported.css" supports(display: block) screen;body{font-family:Arial, sans-serif;font-size:16px;line-height:1.5;}@media screen and (min-width: 768px){body{font-size:18px;}}
```

### Save to file

[](#save-to-file)

Instead of outputting the compiled css, it can be saved to a file:

```
$minify = true; // Will override minify option if already set
$override = true; // Override if file exists
$mkdir    = true; // Creates directory recursively if not already exists
$css->save('path/to/compiled.css', $minify, $override, $mkdir);
```

### Import rules from another instance of CSS class

[](#import-rules-from-another-instance-of-css-class)

```
use Devly\CssGenerator\CSS;

$imported = CSS::new()->selector('body')->backgroundColor('#000000');

$css = CSS::new($imported)
```

In addition, it is possible to import CSS into media() statement:

```
use Devly\CssGenerator\CSS;

$mobile_css = CSS::new()->selector('body')->backgroundColor('#000000');

$css = CSS::new()->media('screen and (max-width: 768px)', $mobile_css);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~851 days

Total

2

Last Release

715d ago

Major Versions

0.1.0 → 1.0.02024-06-02

PHP version history (2 changes)0.1.0PHP ^7.4

1.0.0PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![valenjeb](https://avatars.githubusercontent.com/u/7081274?v=4)](https://github.com/valenjeb "valenjeb (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devly-css-generator/health.svg)

```
[![Health](https://phpackages.com/badges/devly-css-generator/health.svg)](https://phpackages.com/packages/devly-css-generator)
```

###  Alternatives

[eecli/bootstrap

Bootstrap the ExpressionEngine environment

349.9k1](/packages/eecli-bootstrap)[lambert/tree-shape

A simple way to generate a tree structure.

186.0k](/packages/lambert-tree-shape)[bratao/prediction-io

Laravel PredictionIO Client

241.6k](/packages/bratao-prediction-io)

PHPackages © 2026

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