PHPackages                             10quality/php-css-color-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. 10quality/php-css-color-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

10quality/php-css-color-parser
==============================

Package used to parse CSS colors in order to normalize them into different formats.

v1.0.5(8y ago)515.7k↓16.7%1MITPHPPHP &gt;=5.4

Since Mar 13Pushed 7y ago2 watchersCompare

[ Source](https://github.com/10quality/php-css-color-parser)[ Packagist](https://packagist.org/packages/10quality/php-css-color-parser)[ Docs](https://github.com/10quality/php-css-color-parser)[ RSS](/packages/10quality-php-css-color-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

CSS Color Parser
================

[](#css-color-parser)

[![Latest Stable Version](https://camo.githubusercontent.com/bd3699383989093ce0c2930e7731009c5e108c170884e4ab36c0a86d918c3e12/68747470733a2f2f706f7365722e707567782e6f72672f31307175616c6974792f7068702d6373732d636f6c6f722d7061727365722f762f737461626c65)](https://packagist.org/packages/10quality/php-css-color-parser)[![Total Downloads](https://camo.githubusercontent.com/da326df35fc8c98f544d7b1ab7b9ea10d7fd26727d622fef6f9b4586ecd3ff4f/68747470733a2f2f706f7365722e707567782e6f72672f31307175616c6974792f7068702d6373732d636f6c6f722d7061727365722f646f776e6c6f616473)](https://packagist.org/packages/10quality/php-css-color-parser)[![License](https://camo.githubusercontent.com/3b0cb97d66ed3ca3273b8ff671f31efc347466403fa5f74c7257a09966aca3b7/68747470733a2f2f706f7365722e707567782e6f72672f31307175616c6974792f7068702d6373732d636f6c6f722d7061727365722f6c6963656e7365)](https://packagist.org/packages/10quality/php-css-color-parser)

A little package used to parse CSS colors in order to normalize them into different formats (supported: hex, argb and rgba).

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4

Install
-------

[](#install)

```
composer require 10quality/php-css-color-parser
```

Usage
-----

[](#usage)

Use statement:

```
use TenQuality\Utility\Color\CssParser;
```

For a normalized HEX code:

```
// This will echo "#44FCCD"
echo CssParser::hex('#44fCCd');

// This will echo "#44FFFF"
echo CssParser::hex('#4ff');

// This will echo "#FFFFFF"
echo CssParser::hex('white');

// This will echo "#89CC7F"
echo CssParser::hex('89cc7F');
```

For a normalized HEX code (with transparency):

```
// This will echo "#44FCCD44"
echo CssParser::hexTransparent('#44fCCd44');

// This will echo "#44FFFFFF"
echo CssParser::hexTransparent('#4ff');

// This will echo "#FFFFFFFF"
echo CssParser::hexTransparent('white');
```

For ARGB:

```
// This will echo "0x4444FCCD"
echo CssParser::argb('#44fCCd44');

// This will echo "0xFF44FFFF"
echo CssParser::argb('#4ff');

// This will echo "0xFFFFFFFF"
echo CssParser::argb('white');
```

For RGBA:

```
// This will echo "rgba(57,115,157,0.53)"
echo CssParser::rgba('#39739d88');

// This will echo "rgba(255,255,255,1)"
echo CssParser::rgba('white');
```

### Casting

[](#casting)

To return the color's rgba codes as an array:

```
// This will dump the following array "[57,115,157,255]"
var_dump(CssParser::array('#39739d'));
```

To return the color's rgba codes as a JSON string:

```
// This will echo "{"red":57,"green":115,"blue":157,"alpha":255}"
echo CssParser::string('#39739d');
```

### Alpha

[](#alpha)

Default alpha can be changed from `FF` to `00` by calling to the following static method:

```
CssParser::setAlpha('0');
// Or
CssParser::setAlpha(CssParser::ALPHA_TRANSPARENT);
```

Resulting in:

```
// This will echo "#44FFFF00"
echo CssParser::hexTransparent('#4ff');

// This will echo "rgba(255,255,255,0)"
echo CssParser::rgba('white');

// This will echo "0x0044FFFF"
echo CssParser::argb('#4ff');
```

To restore the default alpha call:

```
CssParser::setAlpha('F');
// Or
CssParser::setAlpha(CssParser::ALPHA_OPAQUE);
```

### Extending named colors

[](#extending-named-colors)

To add more CSS named colors:

```
// This will exho "#00008B"
echo CssParser::hex('darkblue', ['/darkblue/','/darkgreen/'], ['00008B','006400']);
```

**NOTE:** Second parameter passed by containes the list of additional css labels (names) to parse and the third paramener contains its HEX code in caps and without the hashtag character.

Copyright &amp; License
-----------------------

[](#copyright--license)

MIT License.

(c) 2018 [10 Quality](https://www.10quality.com/)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 84.6% 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 ~3 days

Total

6

Last Release

2972d ago

### Community

Maintainers

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

---

Top Contributors

[![amostajo](https://avatars.githubusercontent.com/u/1645908?v=4)](https://github.com/amostajo "amostajo (11 commits)")[![iBotPeaches](https://avatars.githubusercontent.com/u/611784?v=4)](https://github.com/iBotPeaches "iBotPeaches (2 commits)")

---

Tags

normalizeparsercsscolorhexrgbaargb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/10quality-php-css-color-parser/health.svg)

```
[![Health](https://phpackages.com/badges/10quality-php-css-color-parser/health.svg)](https://phpackages.com/packages/10quality-php-css-color-parser)
```

###  Alternatives

[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[scotteh/php-dom-wrapper

Simple DOM wrapper to select nodes using either CSS or XPath expressions and manipulate results quickly and easily.

1471.9M10](/packages/scotteh-php-dom-wrapper)[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.7M16](/packages/ozdemirburak-iris)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.1M10](/packages/ssnepenthe-color-utils)[mishal/iless

Less.js port to PHP

4737.0k3](/packages/mishal-iless)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)

PHPackages © 2026

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