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(2y ago)1277MITPHPPHP &gt;=7.4

Since Feb 2Pushed 2y 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 1w 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

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

807d 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 (4 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

[ip2location/ip2location-laravel

Lookup for visitor's IP information, such as country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type.

83562.9k1](/packages/ip2location-ip2location-laravel)[kartik-v/yii2-social

Module containing useful widgets for Yii Framework 2.0 that integrates social functionalities from DISQUS, Facebook, Google etc.

91265.7k8](/packages/kartik-v-yii2-social)[typo3/cms-introduction

The Official TYPO3 Introduction Package

1883.5k6](/packages/typo3-cms-introduction)[alt-design/alt-sitemap

Alt Sitemap addon, create a sitemap from Statamic entries

1224.7k](/packages/alt-design-alt-sitemap)

PHPackages © 2026

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