PHPackages                             shulyak/crossjoin-css - 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. shulyak/crossjoin-css

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

shulyak/crossjoin-css
=====================

CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources. Requires PHP 5.4+.

1.0.0(4y ago)099MITPHPPHP &gt;=5.4.0

Since Nov 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/shulyak/crossjoin-css)[ Packagist](https://packagist.org/packages/shulyak/crossjoin-css)[ RSS](/packages/shulyak-crossjoin-css/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

\#CSS reader and writer

\##Introduction CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources.

\##Installation This is a composer package. See the [composer website](https://getcomposer.org/) for basic installation information.

Add the following line to your `composer.json` file:

```
{
    "require": {
        "shulyak/crossjoin-css": "1.0.*"
    }
}
```

\###Requirements

- PHP 5.4+
- Multibyte String (mbstring) extension
- DOM extension (to extract CSS from HTML sources)

\##Features

- Full CSS3 support
- Full Unicode support
- Support for huge parts of CSS4
- Supports at-rules with an unlimited level of nesting
- Supports CSS comments
- Can handle large, compressed CSS files
- Integrated checks for invalid CSS
- ...

\##Basic usage

\###Reading CSS You can read the CSS information from different sources.

```
// Read CSS file
$cssFileName = "path/to/file.css";
$reader = new \Crossjoin\Css\Reader\CssFile($cssFileName);

// Read CSS string
$cssString = "body { background:red; }";
$reader = new \Crossjoin\Css\Reader\CssFile($cssString);

// Extract CSS from  tags in a HTML file
// (multiple tags are merges to one style sheet)
$htmlFileName = "path/to/file.html";
$reader = new \Crossjoin\Css\Reader\HtmlFile($htmlFileName);

// Extract CSS from  tags in a HTML string
// (multiple tags are merges to one style sheet)
$htmlString = "body{color:red;}";
$reader = new \Crossjoin\Css\Reader\HtmlFile($htmlString);
```

\###Charset detection The charset of the CSS file is detected automatically (depending on Byte-Order-Markers or a charset rule within the CSS) and defaults to "UTF-8". You can change the default value by setting the environment encoding.

```
// Sets the environment encoding of the referencing (!) document, e.g. if defined
// in a link tag of an HTML page.
// This is used as a fall back value to determine the charset of the CSS file.
$reader->setEnvironmentEncoding("UTF-8");
```

\###Writing CSS The writer can create CSS in different formats.

```
// Gets the CSS content in compact format (no comments, no line breaks,...)
$writer = new \Crossjoin\Css\Writer\Compact($reader->getStyleSheet());
$cssContent = $writer->getContent();

// Gets the CSS content in prettified format
// (with comments, line breaks, indentations,...)
$writer = new \Crossjoin\Css\Writer\Pretty($reader->getStyleSheet());
$cssContent = $writer->getContent();
```

\###Error handling While parsing the CSS source, the content is checked for invalid rules, selectors and declarations. Furthermore the reader and the writer do additional checks regarding the composition of the rules, e.g. invalid rule positions or unnecessary empty rules.

```
$cssString = 'body{color:black} @charset "UTF-8"; @media print{@page{margin:1cm;}}';
$reader = new \Crossjoin\Css\Reader\CssString($cssString);
$writer = new \Crossjoin\Css\Writer\Pretty($reader->getStyleSheet());
$content = $writer->getContent();
$errors = $writer->getErrors();

print_r($content);
// body { color: black; }

print_r($errors);
// Array (
// [0] => Ignored @charset rule, because at wrong position in style sheet.
// [1] => Rule instance of type 'Crossjoin\Css\Format\Rule\AtPage\PageRule'
//        not allowed in conditional group rule of type
//        'Crossjoin\Css\Format\Rule\AtMedia\MediaRule'.
// [2] => Empty media at-rule '@media print' ignored.
// )
```

\##Advanced usage TODO

\##To Do

- Additional checks for valid CSS rules, properties and values
- Additional optimizations of CSS properties and values
- Optimized auto-correction of invalid CSS, following the specs ([example](http://dev.w3.org/csswg/mediaqueries-4/#error-handling))
- Support for [CSS Paged Media Module Level 3](http://dev.w3.org/csswg/css-page-3/#at-page-rule) (page type selectors, margin at-rules)
- Support for "supports" in import at-rule ([not final](http://dev.w3.org/csswg/css-cascade-4/#at-ruledef-import))

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

1648d ago

### Community

Maintainers

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

---

Top Contributors

[![sh00lik](https://avatars.githubusercontent.com/u/64553941?v=4)](https://github.com/sh00lik "sh00lik (1 commits)")

---

Tags

phpcsscss parsercss readercss writer

### Embed Badge

![Health badge](/badges/shulyak-crossjoin-css/health.svg)

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

###  Alternatives

[wikimedia/less.php

PHP port of the LESS processor

12327.4M77](/packages/wikimedia-lessphp)[nlac/nlsclientscript

Yii ClientScript extension for prevent reloading javascript and merging/minfying resources

208.2k](/packages/nlac-nlsclientscript)[tailwindphp/tailwindphp

A full port of TailwindCSS 4.x to PHP

171.7k1](/packages/tailwindphp-tailwindphp)

PHPackages © 2026

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