The Color Chips plugin extends Expressive Code to display a preview “chip” for colors in CSS code blocks.
This guide will show you how to add it to your website.
Set-up
Install the expressive-code-color-chips
dependency using your preferred package manager:
npm i expressive-code-color-chips
yarn add expressive-code-color-chips
pnpm add expressive-code-color-chips
Add the plugin to your site’s Expressive Code configuration:
import { defineConfig } from ' astro/config ' ;
import astroExpressiveCode from ' astro-expressive-code ' ;
import { pluginColorChips } from ' expressive-code-color-chips ' ;
export default defineConfig ({
plugins: [ pluginColorChips ()],
import { defineConfig } from ' astro/config ' ;
import starlight from ' @astrojs/starlight ' ;
import { pluginColorChips } from ' expressive-code-color-chips ' ;
export default defineConfig ({
title: ' My Starlight site ' ,
plugins: [ pluginColorChips ()],
import createMDX from ' @next/mdx ' ;
import rehypeExpressiveCode from ' rehype-expressive-code ' ;
import { pluginColorChips } from ' expressive-code-color-chips ' ;
/** @type {import('rehype-expressive-code').RehypeExpressiveCodeOptions} */
const rehypeExpressiveCodeOptions = {
plugins: [ pluginColorChips ()] ,
/** @type {import('next').NextConfig} */
pageExtensions: [ ' js ' , ' jsx ' , ' ts ' , ' tsx ' , ' md ' , ' mdx ' ] ,
const withMDX = createMDX ( {
// The nested array structure is required to pass options
[ rehypeExpressiveCode , rehypeExpressiveCodeOptions ],
export default withMDX ( nextConfig );
import { pluginColorChips } from ' expressive-code-color-chips ' ;
plugins: [ pluginColorChips ()],
That’s it! Colors in CSS code blocks will now be annotated with a small preview.
Usage
There is no specific syntax for this plugin.
It detects CSS color syntax in code blocks tagged with css
and annotates all valid colors it finds.
For example the following Markdown code:
Renders a code block with a chip next to the color goldenrod
:
In addition to css
, this plugin also runs for scss
, sass
, less
, and stylus
code blocks.
For example:
Which renders as:
Support
This is open-source software.
If you run into any bugs, please report issues on GitHub .