Termark (= Terminal Markup) is a basic library to format console output to the standard non-browser terminal.
Features
- 0-dependency
- ES module & CommonJS compatible
- NO_COLOR-friendly
- Support for basic ANSI styling, 4-bit, 8-bit, and 24-bit colours
- Gradients
- Built-in terminal logging methods with pre-made styling
- Template strings
- Style nesting
- Colour detection utilities
Installation
npm install termarkESM & CJS compatibility
// CJS:
const termark = require('termark');
// ESM:
import termark from 'termark';Usage
import termark from 'termark';
console.log(
termark.red('This is red text.'),
termark.bgGreen('This text has a green background.'),
termark.cyan`There's support for template strings as well`,
termark.ansi256('text', 33)('This single function handles text and background colour!'),
termark.rgb('background', 42, 122, 255)('This is some dark blue text'),
termark.gradient('text', [[53, 72, 172], [200, 230, 121]])('Gradients are also possible.'),
termark.areColorsEnabled,
termark.is8bitEnabled,
termark.is24bitEnabled
);
Basic ANSI styling
import termark from 'termark';
termark.reset('...');
termark.bold('...');
termark.dim('...');
termark.italic('...');
termark.underline('...');
termark.blink('...');
termark.inverse('...');
termark.overline('...');
termark.hidden('...');
termark.strike('...');
4-bit colours
import termark from 'termark';
termark.black('...');
termark.red('...');
termark.green('...');
termark.yellow('...');
termark.blue('...');
termark.magenta('...');
termark.white('...');
termark.blackBright('...');
termark.redBright('...');
termark.greenBright('...');
termark.yellowBright('...');
termark.blueBright('...');
termark.magentaBright('...');
termark.whiteBright('...');
termark.bgBlack('...');
termark.bgRed('...');
termark.bgGreen('...');
termark.bgYellow('...');
termark.bgBlue('...');
termark.bgMagenta('...');
termark.bgWhite('...');
termark.bgBlackBright('...');
termark.bgRedBright('...');
termark.bgGreenBright('...');
termark.bgYellowBright('...');
termark.bgBlueBright('...');
termark.bgMagentaBright('...');
termark.bgWhiteBright('...');
8-bit colours
import termark from 'termark';
termark.ansi256('text', 33)('...');
termark.ansi256('background', 200)('...');
24-bit colours
import termark from 'termark';
// You can specify your RGB values as an array:
termark.rgb('text', [182, 22, 234])('...');
termark.rgb('background', [200, 0, 184])('...');
// ...or as a simple list of three values:
termark.rgb('text', 182, 22, 234)('...');
termark.rgb('background', 200, 0, 184)('...');
// This method is compatible with `color-convert`:
import convert from 'color-convert';
termark.rgb('text', convert.hex.rgb('008330'))('...');
Gradients
Please note that gradients do not support nested styling.
import termark from 'termark';
termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');
Built-in terminal logging methods
import termark from 'termark';
termark.success('...'); // Logs some message in green as an info message.
termark.info('...'); // Logs some message in blue as an info message.
termark.warning('...'); // Logs some message in yellow as a warning.
termark.error('...'); // Logs some message in red as an error.
// These also support prefixes for branding purposes:
const brandPrefix = termark.blue('Example') + termark.blackBright(' - ');
termark.error('File not found', brandPrefix);
Template strings
import termark from 'termark';
// Instead of using this:
termark.blue('...');
// ...you can use this:
termark.blue`...`;
Nested styles
import termark from 'termark';
termark.blue(
'This is some blue text ' +
termark.yellow('That becomes yellow,') +
' that becomes blue again.'
);
Colour detection utilities
import termark from 'termark';
termark.areColorsEnabled; // Check whether terminal colours are enabled.
termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled.
Licence
Termark is licenced under the Apache licence version 2. The full licence text is present in the source code.
In addition, this snippet of text is present at the top of all files:
Copyright 2025 Q
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Highlighting done with highlight.js.