A csslib project · MIT licensed · v1.0.0

Vektor.css

Charts and graphs in pure, native CSS.

Write a list or a table, set a few custom properties, and get accessible, animated, responsive charts. No JavaScript, no canvas, no build step. Just one stylesheet you can drop into any project.

JavaScript
0 KB
Chart types
7
Dependencies
None
License
MIT
Weekly active users Pure CSS · hover a bar
Install

Add one line to your page.

Link the hosted file or download vektor-1.0.0.css and serve it yourself. Every release keeps its version in the file name, so a link never changes under you. A CDN option is on its way.

Hosted

Straight from csslib.github.io.

<link rel="stylesheet" href="https://csslib.github.io/vektor-1.0.0.css">

CDN Work in progress

A globally cached CDN link is being set up. Use the hosted or self-hosted option for now.

Coming soon

Self-hosted

Download the file and keep it with your assets.

<link rel="stylesheet" href="/css/vektor-1.0.0.css">Download
Quick start

Your first chart in three steps.

  1. Link the stylesheet

    Add vektor-1.0.0.css to the <head> of your page.

  2. Add a scope

    Wrap charts in an element with class="vk-scope" so they get fonts, colours and container queries.

  3. Write your data

    Each item sets --val from 0 to 100. Labels come from data-label.

index.html
<link rel="stylesheet" href="https://csslib.github.io/vektor-1.0.0.css">

<div class="vk-scope" data-theme="light">
  <ul class="vk-chart vk-bar vk-grid-y" style="--target: 80" data-target-label="Goal: 80%">
    <li style="--val: 65" data-label="Q1" data-value="65%"></li>
    <li style="--val: 88" data-label="Q2" data-value="88%"></li>
    <li style="--val: 74" data-label="Q3" data-value="74%"></li>
  </ul>
</div>
Reference

Classes, properties and tokens.

Values are plain numbers from 0 to 100 unless noted. Every chart also accepts --c on an item to set its colour.

Chart types

ClassMarkupProperties & attributes
.vk-chart.vk-bar<ul> of <li>, or a <table> with <tr> rows--val, data-label, data-value, data-alert="high", data-series
.vk-bar-multiEach <li> holds .vk-seg segments--val per segment; add .vk-grouped for side-by-side bars
.vk-chart.vk-hbar<li> with .vk-hbar-label, .vk-hbar-track > .vk-hbar-fill, .vk-hbar-val--val
.vk-chart.vk-radar<li> with .vk-radar-stem and .vk-radar-point--total on the list; --i (0-based index), --val, data-label per item
.vk-chart.vk-heatmapGrid of .vk-heatmap-col-header, .vk-heatmap-label and .vk-heatmap-cell--cols on the grid; --val per cell
.vk-chart.vk-range.vk-range-row containing .vk-range-track with whisker, box and median--min, --q1, --med, --q3, --max
.vk-donutElement with an optional .vk-donut-center--s1, --s2, --s3 (segment percentages), --_size, --_thickness
.vk-gaugeElement with an optional .vk-gauge-readout--val, --c

Modifiers & helpers

.vk-scope
Wrapper that applies fonts, colours, legend filtering and the vk-card container query.
.vk-grid-y / .vk-grid-x
Horizontal or vertical background gridlines.
--target + data-target-label
Draws a labelled threshold line on bar charts.
.vk-values-visible
Always show value pills instead of only on hover.
.vk-legend, .vk-legend-item[data-series]
Hovering a legend item dims every other series with :has().
.vk-sr-only
Keeps table cells readable by screen readers while hidden visually.

Theme tokens

--vk-seed
Brand colour; also the first series colour and the heatmap base.
--vk-c-1 … --vk-c-5, --vk-c-danger
Series palette and alert colour.
--vk-bg, --vk-surface, --vk-text, --vk-text-muted
Surface and text colours. Dark by default; add data-theme="light" to any ancestor.
--vk-radius, --vk-gap, --vk-chart-height
Shape and spacing.
--vk-duration, --vk-ease
Timing for value transitions.
--vk-font-sans, --vk-font-mono
Typefaces for labels and numbers.
Theming example
:root {
  --vk-seed: #e63e14;
  --vk-c-2: #0ea5e9;
  --vk-radius: 10px;
  --vk-chart-height: 300px;
}
Why native CSS

Built on modern CSS, not JavaScript.

@property

Animated data

Typed custom properties let --val transition smoothly whenever your data changes.

sin() · cos()

Real geometry

Radar points sit on true polar coordinates calculated by the browser.

color-mix(in oklch)

One seed colour

Heatmaps, borders and hover states are derived from a single brand colour.

:has()

Zero-JS filtering

Hover a legend item and every other series fades, with no event listeners.

@container

Card-aware

Charts adapt to the width of their card, not the browser window.

@layer

No specificity wars

Everything lives in vektor.* cascade layers, so your own styles always win.

Compatibility

Works in every modern browser.

Vektor.css relies on @property, trigonometric functions, color-mix(), :has(), container queries and cascade layers. Charts are plain lists and tables, so content stays readable anywhere and to assistive technology.

  • Chrome & Edge111+
  • Safari16.4+
  • Firefox128+

Ship your next chart without a chart library.

Vektor.css is free and MIT licensed. Use it in personal and commercial projects.