PHPackages                             loilo/lowlight - 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. loilo/lowlight

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

loilo/lowlight
==============

Show syntax-highlighted code of 150+ languages in your terminal

2.0.0(6y ago)201.6k11BSD-3-ClausePHPPHP &gt;= 7.2CI failing

Since Aug 22Pushed 5y ago2 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (6)Used By (1)

 [![Lowlight logo showing a couch and a shade lamp](lowlight.png)](lowlight.png)

Lowlight
========

[](#lowlight)

[![Tests](https://camo.githubusercontent.com/773adba696c6265907fb92d1e3aa5d8ab1fdb75b65d9f5f79d7c4d634144f01b/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f6c6f696c6f2f4c6f776c696768742f6d6173746572)](https://github.com/loilo/Lowlight/actions)[![Packagist](https://camo.githubusercontent.com/8e3c2713115d4502365544edec2f9f81c26772b920ef1557fe4c8f3b66179bd9/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6c6f696c6f2f4c6f776c69676874)](https://packagist.org/packages/loilo/Lowlight)

Lowlight shows syntax-highlighted code of 150+ languages in your terminal. It's built on top of [highlight.php](https://github.com/scrivo/highlight.php).

[![Part of Lowlight's source code, highlighted with Lowlight](screenshot.png)](screenshot.png)

Installation
------------

[](#installation)

This package is available via Composer. To add it to your project, just run:

```
composer require loilo/lowlight

```

Usage
-----

[](#usage)

### Preconditions

[](#preconditions)

If you're not running Lowlight in a framework context, you may need to initialize Composer's autoloading first:

```
require_once __DIR__ . '/vendor/autoload.php';

```

### Getting Started

[](#getting-started)

To highlight a piece of PHP code, do this:

```
$ll = new Lowlight\Lowlight;

echo $ll->highlight('php', $somePhpSnippet)->value;

```

There are a lot of languages available. See the full list [here](https://github.com/scrivo/highlight.php/tree/master/Highlight/languages).

### Automatic Language Detection

[](#automatic-language-detection)

If you're handling user-provided code, you may not always know the used language. That's where auto detection comes into play.

Let's say we got configuration code, but we aren't sure if it's JSON, YAML or INI, then the following approach would highlight it appropriately:

```
$ll = new Lowlight\Lowlight;

echo $ll->highlightAuto($userProvidedCode, [ 'json', 'yaml', 'ini' ])->value;

```

The second argument to the `highlightAuto()` method are the languages the code will be checked against.

- Passing the parameter is optional. It defaults to `[ 'xml', 'json', 'javascript', 'css', 'php', 'http' ]`.
- You can adjust the default detection languages by calling ```
    $ll->setDefaultAutodetectLanguages([ 'json', 'yaml', 'ini' ]);

    ```

### Theming

[](#theming)

Theming works in analogy to highlight.js' theming. Highlight.js represents each token as CSS class name (e.g. `hljs-comment`) while Lowlight uses the tokens as keys in a theming array:

```
$ll->theme['comment'] = 'green';

```

As you can see, styling is quite limited in the terminal. Lowlight only allows you to set a token's text color, nothing else. Therefore, you usually won't be able to create the same amount of atmosphere through a theme as you can do in CSS (except, maybe, when using arbitrary RGB colors).

#### Colors

[](#colors)

Available colors are:

- `default` (the terminal's default text color)
- `black`
- `gray` / `grey` (actually the same)
- `white`, `bright-white`
- `red`, `bright-red`
- `green`, `bright-green`
- `yellow`, `bright-yellow`
- `blue`, `bright-blue`
- `magenta`, `bright-magenta`
- `cyan`, `bright-cyan`

#### RGB Colors

[](#rgb-colors)

Many modern terminals do support a 24-bit color palette. Instead of using the 16ish oldschool color names, you can provide an RGB array for a token:

```
$ll->theme['comment'] = [ 0, 175, 95 ];

```

If you want to use those, detecting support for 24-bit colors (as with all color-related features) is up to you.

#### Custom themes

[](#custom-themes)

To roll your own theme, it's a viable approach to take [an existing highlight.js theme](https://github.com/highlightjs/highlight.js/tree/master/src/styles), extract all `.hljs-xxx` classes and transform them to a PHP associative array.

> **Note:** You usually don't know the general style of the user's terminal and how your theme integrates with that (most notably if they're using a dark or a light theme), so be careful and restrictive with the colors you use.

By the way, this is Lowlight's default theme:

```
$ll->theme = [
    'comment' => 'gray',
    'string' => 'blue',
    'number' => 'green',
    'literal' => 'bright-green',
    'meta' => 'cyan',
    'meta-string' => 'bright-cyan',

    'keyword' => 'yellow',
    'attribute' => 'yellow',
    'selector-tag' => 'yellow',
    'meta-keyword' => 'yellow',
    'doctag' => 'yellow',
    'name' => 'yellow',

    'type' => 'red',
    'subst' => 'red',
    'selector-id' => 'red',
    'selector-class' => 'red',
    'quote' => 'red',
    'template-tag' => 'red',
    'deletion' => 'red',

    'title' => 'magenta',
    'section' => 'magenta',
    'built_in' => 'magenta',

    'regexp' => 'bright-red',
    'symbol' => 'bright-red',
    'variable' => 'bright-red',
    'template-variable' => 'bright-red',
    'link' => 'bright-red',
    'selector-attr' => 'bright-red',
    'selector-pseudo' => 'bright-red',

    'built' => 'green',
    'bullet' => 'green',
    'code' => 'green',
    'addition' => 'green',

    'emphasis' => 'red',
    'strong' => 'red'
];

```

Credit
------

[](#credit)

- [highlight.php](https://github.com/scrivo/highlight.php) (a port of [highlight.js](https://github.com/highlightjs/highlight.js)) is a syntax highlighter with HTML output. It does most of Lowlight's heavy lifting. Check it out!
- Lowlight's logo is based on [a graphic](https://github.com/twitter/twemoji/blob/master/assets/svg/1f6cb.svg) from the [Twemoji Project](https://github.com/twitter/twemoji) (licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 95.2% 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 ~192 days

Total

4

Last Release

2283d ago

Major Versions

1.0.2 → 2.0.02020-03-23

PHP version history (2 changes)1.0.0PHP &gt;= 5.6

2.0.0PHP &gt;= 7.2

### Community

Maintainers

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

---

Top Contributors

[![loilo](https://avatars.githubusercontent.com/u/1922624?v=4)](https://github.com/loilo "loilo (20 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/loilo-lowlight/health.svg)

```
[![Health](https://phpackages.com/badges/loilo-lowlight/health.svg)](https://phpackages.com/packages/loilo-lowlight)
```

###  Alternatives

[ueberdosis/tiptap-php

A PHP package to work with Tiptap output

26712.7M51](/packages/ueberdosis-tiptap-php)[contao/core-bundle

Contao Open Source CMS

1231.6M2.6k](/packages/contao-core-bundle)[spatie/laravel-mailcoach-editor

An Editor editor package for Mailcoach

11252.2k1](/packages/spatie-laravel-mailcoach-editor)

PHPackages © 2026

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