Styling Guide

Learn how to customize svelte-rune-highlight components using CSS variables, custom classes, and Tailwind CSS

Overview

svelte-rune-highlight is a CSS framework-free library. You can customize it using CSS custom properties (variables), custom classes, or Tailwind CSS utilities. All components are designed to work seamlessly with any styling approach.

1. CSS Custom Properties (Recommended)

The easiest way to customize components globally is through CSS variables. Add these to your global stylesheet:

Available CSS Variables

Variable Default Description
--code-padding 1rem Padding inside code blocks
--code-font-family 'Fira Code', monospace Font family for code
--code-font-size 0.875rem Font size for code text
--code-line-height 1.5 Line height for code
--langtag-background rgba(0, 0, 0, 0.1) Language tag background
--langtag-color currentColor Language tag text color
--highlighted-background rgba(254, 241, 96, 0.2) Highlighted line background
--line-number-color currentColor Line number color

2. Custom Classes

Pass custom classes to components for specific styling:

💡 Tip: Use :global() in Svelte to style components from parent scopes.

3. Tailwind CSS Utilities

If your project uses Tailwind CSS, you can leverage its utility classes for quick styling. Define reusable component classes:

Usage Examples

4. Highlight.js Themes

Change syntax highlighting colors by importing different highlight.js themes:

Popular themes: github-dark, atom-one-dark, monokai, nord

Live Examples

Tailwind: Modern Bordered

Tailwind: Card Style

Tailwind: Gradient Border

CSS Variables: Purple Theme

CSS Variables: Retro Terminal

Built-in CSS Classes

The library includes several built-in CSS classes you can override:

Class Name Used In Purpose
.hlc-base HighlightCompo Base container styling
.hlc-warning All components Warning messages in DEV mode
.hlc-error HighlightSvelte Error messages
.hlc-empty-code HighlightSvelte Empty code message
.cw-base ExampleWrapper Wrapper container
.cw-inner ExampleWrapper Inner content area

When to Use Each Method

CSS Custom Properties

Best for:

  • Global theming across entire site
  • Dynamic theme switching
  • Framework-agnostic projects
  • Fine-tuned control over properties

Tailwind CSS

Best for:

  • Quick prototyping and iteration
  • Consistent spacing and sizing
  • Responsive designs
  • Modern effects (shadows, gradients)

Custom Classes

Best for:

  • Component-specific styling
  • Complex animations
  • Unique design requirements
  • Reusable component patterns

Highlight.js Themes

Best for:

  • Syntax highlighting colors
  • Pre-made color schemes
  • Matching IDE themes
  • Quick theme changes

Resources