Convert EBC (European Brewery Convention) or SRM (Standard Reference Method) beer color values to RGB hex codes with scientific accuracy. Zero dependencies, fully typed, and ultra-lightweight (~2kB bundle size).
beer-color-rgb takes an EBC or SRM value and converts it to a precise RGB color. It uses the A.J. de Lange spectral model — a scientifically validated method based on light transmission analysis of 99 real beers — producing colorimetrically accurate results suitable for brewing apps, color pickers, and design systems.
One package to rule them all, One library to type them, One plugin to style them all, Or in the CLI compile them.
Choose how you want to integrate it into your workflow:
- As a core TypeScript library for direct color conversion logic.
- As a Tailwind CSS v4 plugin to auto-generate color utility classes.
- As a CLI tool to generate static JSON/CSS color palettes.
Prerequisites:
npm install beer-color-rgbimport { ebcToHex, ebcToRgb, ebcToRgbObject, srmToHex } from "beer-color-rgb";
// EBC
ebcToHex(20); // → "#b95900"
ebcToRgb(20); // → "rgb(185, 89, 0)"
ebcToRgbObject(20); // → { r: 185, g: 89, b: 0 }
// SRM
srmToHex(10); // → "#ba5b00"
// Custom optical path (cm)
ebcToHex(20, { lightPath: 3 }); // → "#d88900"# Single EBC conversion
npx beer-color-rgb 20
# → #b95900
# Single SRM conversion
npx beer-color-rgb --srm 10
# → #ba5b00
# Batch CSS generation
npx beer-color-rgb generate --format css --unit ebc --output colors.css
# Batch JSON generation
npx beer-color-rgb generate --format json --unit srm --output colors.json
# Custom optical path
npx beer-color-rgb 20 --path 3
# → #d88900Tailwind CSS v4 (Recommended):
@import "tailwindcss";
@plugin "beer-color-rgb/plugin";
/* Optional: configure via @theme */
@theme {
--beer-light-path: 3; /* optical path in cm, default 5 */
--beer-ebc-start: 1; /* EBC range start, default 1 */
--beer-ebc-end: 20; /* EBC range end, default 80 */
--beer-srm-start: 1; /* SRM range start, default 1 */
--beer-srm-end: 15; /* SRM range end, default 40 */
}Tailwind CSS v3 (Legacy):
// tailwind.config.ts
import { beerColorPlugin } from "beer-color-rgb/plugin";
export default {
plugins: [beerColorPlugin()],
};This generates utility classes for EBC 1–80 and SRM 1–40:
<div class="ebc-bg-20">...</div>
<div class="srm-bg-10">...</div>
<!-- Decimal values supported, though uncommon in practice -->
<div class="ebc-bg-[35.5]">...</div>Plugin options (v3 JS config — all options available):
beerColorPlugin({
ebcRange: [1, 80], // or false to disable
srmRange: [1, 40], // or false to disable
lightPath: 5, // optical path in cm (default: 5)
});Note: Disabling a range entirely (
false) is v3/JS-only. In v4, use@themevariables to restrict the range.
beer-color-rgb/
├── src/
│ ├── convert.ts # Core conversion logic (A.J. de Lange spectral model)
│ ├── index.ts # Public API exports
│ ├── cli.ts # Command-line interface
│ └── plugin.ts # Tailwind CSS plugin
├── tests/
│ ├── convert.test.ts
│ ├── index.test.ts
│ └── plugin.test.ts
├── package.json
├── tsconfig.json
└── CHANGELOG.md
None required. The conversion uses fixed CIE 1931 colorimetric data and D65 illuminant (standard daylight).
EBC functions
ebcToHex(ebc: number, options?: ColorOptions): string
// → "#b95900"
ebcToRgb(ebc: number, options?: ColorOptions): string
// → "rgb(185, 89, 0)"
ebcToRgbObject(ebc: number, options?: ColorOptions): { r: number; g: number; b: number }
// → { r: 185, g: 89, b: 0 }
ebcToRgbArray(ebc: number, options?: ColorOptions): [number, number, number]
// → [185, 89, 0]SRM functions (SRM × 1.97 = EBC internally)
srmToHex(srm: number, options?: ColorOptions): string
srmToRgb(srm: number, options?: ColorOptions): string
srmToRgbObject(srm: number, options?: ColorOptions): { r: number; g: number; b: number }
srmToRgbArray(srm: number, options?: ColorOptions): [number, number, number]ColorOptions
type ColorOptions = {
lightPath?: number; // Optical path in cm (default: 5.0)
};lightPath |
Use case |
|---|---|
5.0 (default) |
BJCP standard — typical glass viewed in daylight |
3.0 |
Aesthetic middle ground — richer apparent color |
1.27 |
ASBC/EBC laboratory measurement standard |
The A.J. de Lange spectral model reconstructs the light transmission spectrum for a given EBC value, then converts the result to sRGB using CIE 1931 colorimetry with D65 (6500K daylight) illumination.
Pipeline:
EBC → Spectral transmission T(λ) → XYZ tristimulus → sRGB linear → sRGB gamma correction → #RRGGBB
This approach is more accurate than polynomial or exponential approximations, especially for pale beers (EBC 1–20) and dark beers (EBC 50+).
- A.J. de Lange — "Color" in Bamforth's Brewing Materials and Processes (2016) — double-exponential Beer-Lambert model fitted on 99 real beers
- Thomas Ascher / olfarve — github.com/aschet/olfarve — reference implementation in Python, JS, C++, Go and more (MIT License)
- CIE 1931 — CIE 1931 color space — 2° standard observer color matching functions (x̄, ȳ, z̄) and D65 illuminant spectral data
- IEC 61966-2-1 / sRGB — sRGB standard — XYZ→linear sRGB matrix and gamma transfer function
- BJCP Color Guide — bjcp.org/education-training/education-resources/color-guide — defines the 5 cm optical path as the standard for beer color perception
MIT — see LICENSE file.