Skip to content

Custom Styling

The viewer ships a single stylesheet and exposes stable, prefixed CSS classes (jv-*) you can target to customize its appearance beyond the built-in themes.

Importing the Stylesheet

The component's styles are not injected automatically — import them once, anywhere in your app:

ts
import '@anilkumarthakur/vue3-json-viewer/styles.css';

One import is enough

Import it a single time (e.g. in your entry file). The package marks CSS as a side effect so bundlers keep it.

Overriding Styles

Every element carries a jv--prefixed class. Override them in your own (non-scoped) CSS. For example, to enlarge the font and tweak the container:

css
.jv-node {
  font-size: 14px;
  font-family: 'SFMono-Regular', ui-monospace, monospace;
}

.jv-root {
  padding: 24px;
  border-radius: 12px;
}

Class Reference

Layout

ClassElement
jv-nodeEvery node wrapper (sets base font)
jv-rootThe outermost node (padding, radius, scroll)
jv-darkApplied to the root in dark mode
jv-lightApplied to the root in light mode
jv-itemA single object/array entry
jv-childrenThe indented container of a node's children
jv-rowOne line (key + value / bracket)

Keys, values & punctuation

ClassElement
jv-keyObject key label
jv-clickableApplied to clickable keys/colons
jv-colonThe : between key and value
jv-commaTrailing commas
jv-bracketClosing } / ]
jv-stringString values (+ jv-string-dark/-light)
jv-numberNumber values (+ -dark/-light)
jv-booleanBoolean values (+ -dark/-light)
jv-nullnull / undefined (+ -dark/-light)
jv-dateDate values (+ -dark/-light)
jv-regexpRegExp values (+ -dark/-light)

Controls & badges

ClassElement
jv-root-controlsThe "Expand All / Collapse All" bar
jv-control-btnA root control button (+ -dark/-light)
jv-toggleThe clickable type indicator ({, […])
jv-type-indicatorWrapper around badge + brackets
jv-type-badgeThe small obj / count badge
jv-type-objectObject badge variant
jv-type-arrayArray badge variant
jv-countCollapsed "N keys / N items" label (+ -dark/-light)
jv-copy-btnThe copy button (+ -dark/-light)
jv-primitiveWrapper for a primitive row

Example: Compact, Bordered Theme

css
.jv-root {
  padding: 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
}

.jv-node {
  font-size: 12px;
  line-height: 1.5;
}

/* Always show copy buttons instead of on hover */
.jv-copy-btn {
  opacity: 0.4 !important;
}
.jv-copy-btn:hover {
  opacity: 1 !important;
}

What You Can't Change with Props (Yet)

Value colors are applied inline from a built-in palette (see Dark / Light Mode); there is currently no prop to pass a custom color theme. To recolor values, override the jv-string, jv-number, etc. classes with !important where needed:

css
.jv-string-dark {
  color: #7ee787 !important;
}

The exported ThemeColors / JsonViewerTheme types describe the shape of the built-in palettes for reference.

Released under the MIT License.