PHPackages                             jstewmc/get-style - 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. jstewmc/get-style

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

jstewmc/get-style
=================

Get a css inline style

v1.0.0(9y ago)021MITPHPPHP ^7.0

Since Aug 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jstewmc/get-style)[ Packagist](https://packagist.org/packages/jstewmc/get-style)[ RSS](/packages/jstewmc-get-style/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

get-style
=========

[](#get-style)

Get a Cascading Style Sheet (CSS) inline style from a PHP array.

```
use Jstewmc\GetStyle;

// define your styles
$styles = [
    // the asterisk is a special name for global style declarations
    '*' => [
        'color'     => 'red',
        'font-size' => 'small'
    ],
    'foo' => [
        'color'     => 'blue',
        'font-size' => 'medium'
    ],
    'bar' => [
        'color'     => 'green'
    ]
];

// instantiate the get-style service
$css = new Get($styles);

// get the styles
$css();           // returns "color: red; font-size: small;"
$css('foo');      // returns "color: blue; font-size: medium;"
$css('bar');      // returns "color: green; font-size: small;"
$css('foo bar');  // returns "color: green; font-size: medium;"
```

This library is a (very) simple PHP Cascading Style Sheet (CSS) reader. It does not claim to be a full CSS parser! There are several of those already. This library is just a quick and easy way to produce inline CSS from an array of styles.

Names
-----

[](#names)

This library has no concept of CSS selectors! Style names are treated as array keys. They can be any valid string. For example, `p`, `a.foo`, `.foo`, and `foo` are all valid style names.

Keep in mind, the asterisk (`*`) is a special style name that's treated as the global default style. If an asterisk style is defined, all styles will start with its declarations.

Declarations
------------

[](#declarations)

This library merges style declarations like CSS. Given a space-separated string of style names (e.g., `"foo bar baz"`), it will merge the declarations with later declarations taking precedence over previous ones (i.e., `"foo < bar < baz"`).

Keep in mind, this libary is not smart! It requires (very) simple style declarations.

### Use valid declarations

[](#use-valid-declarations)

This library makes no effort to validate your declarations. Make sure your CSS declarations are valid. Otherwise, you will have layout issues.

### Avoid short-hand declarations

[](#avoid-short-hand-declarations)

Short-hand CSS declarations like `"margin" => "0 0 10px"` cannot be merged intelligently with other declarations.

For example:

```
use Jstewmc\GetStyle;

// this will not work!
$styles1 = [
    '*' => [
        'margin' => '0 0 10px'
    ],
    'foo' => [
        'margin-top' => '15px'
    ]
];

// this will work!
$styles2 = [
    '*' => [
        'margin-top'    => '0',
        'margin-left'   => '0',
        'margin-right'  => '0',
        'margin-bottom' => '10px'
    ],
    'foo' => [
        'margin-top' => '15px'
    ]
];

// create two css services
$css1 = new Get($styles1);
$css2 = new Get($styles2);

$css1('foo');  // returns "margin: 0 0 10px; margin-top: 15px;"
$css2('foo');  // returns "margin-top: 15px; margin-left: 0; ... "
```

### Watch quotes

[](#watch-quotes)

This library will not quote space-separated styles. Make sure you quote any space-separated styles in your declarations like `"Courier New"`.

```
use Jstewmc\GetStyle;

// this will not work!
$styles1 = [
    '*' => [
        'font-family' => 'Courier New'
    ]
];

// this will work!
$styles2 = [
    '*' => [
        'font-family' => '\'Courier New\''
    ]
];

// create two css services
$css1 = new Get($styles1);
$css2 = new Get($styles2);

$css1();  // returns "font-family: Courier New;"
$css2();  // returns "font-family: 'Courier New';"
```

Keep in mind, if you are outputting your css as an inline style, make sure your CSS quotes don't collide with the quotes in your HTML source code.

For example:

```
use Jstewmc\GetStyle;

$styles = [
    '*' => [
        'font-family' => '"Courier New"'
    ]
];

$css = new Get($styles);

echo 'Hello world!'
```

The example above will produce the following broken HTML:

```
Hello world!
```

### Avoid space-separated declarations

[](#avoid-space-separated-declarations)

Even if you quote space-separated declarations correctly, you can still run into issues.

An email's HTML body is aggressively line-wrapped at 80 characters or less by some email clients. Newlines in the source code are replaced by spaces, and newlines characters are inserted where needed.

If a newline is inserted at the space in a declaration name, the declaration will break, and the corresponding element will be un-styled. At a minimum, this behavior has been confirmed on OSX 10 running Apple Mail 8.

Author
------

[](#author)

[Jack Clayton](mailto:clayjs0@gmail.com)

License
-------

[](#license)

[MIT](https://github.com/jstewmc/get-style/blob/master/LICENSE)

Version
-------

[](#version)

### 1.0.0, August 16, 2016

[](#100-august-16-2016)

- Major release
- Update `composer.json`
- Update comments

### 0.1.0, August 7, 2016

[](#010-august-7-2016)

- Initial release

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~6 days

Total

2

Last Release

3607d ago

Major Versions

v0.1.0 → v1.0.02016-08-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/50fecae0a7fd2119681bc133e496e7166b01a59f850a3c909e100bd427c6b28b?d=identicon)[Jstewmc](/maintainers/Jstewmc)

---

Top Contributors

[![jstewmc](https://avatars.githubusercontent.com/u/1192893?v=4)](https://github.com/jstewmc "jstewmc (7 commits)")

---

Tags

phpcssstyleinlinejstewmc

### Embed Badge

![Health badge](/badges/jstewmc-get-style/health.svg)

```
[![Health](https://phpackages.com/badges/jstewmc-get-style/health.svg)](https://phpackages.com/packages/jstewmc-get-style)
```

###  Alternatives

[wikimedia/less.php

PHP port of the LESS processor

12328.7M118](/packages/wikimedia-lessphp)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4974.6k1](/packages/yieldstudio-tailwind-merge-php)[tailwindphp/tailwindphp

A full port of TailwindCSS 4.x to PHP

192.5k3](/packages/tailwindphp-tailwindphp)

PHPackages © 2026

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