Highlight Component

A flexible syntax highlighting component with line numbers, language tags, line highlighting, and customizable styling. Supports sticky positioning, custom backgrounds, and advanced features like highlighting specific lines or ranges.

Key Features

  • Optional line numbering with customizable starting number
  • Display language name in top-right corner
  • Highlight specific lines or ranges with custom background
  • Line numbers stay visible while scrolling horizontally
  • Optional line wrapping for long lines
  • Configurable colors, borders, and backgrounds via CSS variables
  • Supports static, relative, absolute, or sticky positioning
  • Powered by highlight.js with language registration
  • Horizontal scroll for wide code blocks
  • Extensive customization through CSS custom properties

Props

PropTypeDefaultDescription
languageHighlightLanguagerequiredLanguage configuration with name and register function
codestring""Code to highlight
numberLinebooleanundefinedShow line numbers
langtagbooleanfalseShow language tag in top-right corner
hideBorderbooleanundefinedHide border between line numbers and code
wrapLinesbooleanundefinedEnable line wrapping
startingLineNumbernumber1Starting line number for display
highlightedLinesnumber[][]Array of line numbers to highlight
highlightedRanges[number, number][][]Array of line ranges to highlight [start, end]
backgroundColorstringundefinedBackground color for line numbers column
position"static" | "relative" | "absolute" | "sticky""sticky"CSS position for line numbers column
classstring"relative"CSS class for the component

Types

Style

Customize the language tag background, color, numberline style and border-radius using style props.

Examples

Basic

The Highlight component requires language and code props. The langtag prop is optional and it will add a language tag.

Markdown

Set langtag and language props to display the language name in the top right corner of the code block.

YAML

JSON

Typescript