CSS gradient visualizing historical temperature data, inspired by Ed Hawkins' Warming Stripes warming-gradient.fvoort.com
README.md

Warming Gradient #

CSS gradient visualizing historical temperature data, inspired by Ed Hawkins' Warming Stripes.

Installation #

You can use NPM (best for projects with a build process), a CDN (quick copy-paste into any HTML file), or download and include the CSS file yourself.

Option 1: Install with NPM #

Make sure you have Node.js installed and run this command in your project folder:

npm install warming-gradient

Import in CSS #

Add this at the top of your main CSS file:

@import 'node_modules/warming-gradient/warming-gradient.css';

Or just paste this <link> in the <head> of your HTML file:

<link rel="stylesheet" href="node_modules/warming-gradient/warming-gradient.css" />

The CSS class and variable will now be available in your project.

Option 2: Use via CDN #

Just paste this <link> in the <head> of your HTML file and the CSS class and variable will be available in your project:

<link rel="stylesheet" href="https://unpkg.com/warming-gradient" />

Option 3: Self-host warming-gradient.css #

  1. Download the warming-gradient.css file from the source files here.
  2. Place it in your project folder.
  3. Include it in your HTML:
<link rel="stylesheet" href="path/to/warming-gradient.css" />

How to use #

Apply the class or variable directly in your HTML, for example:

<!-- Use with class -->
<div class="warming-gradient-global" style="height: 100px"></div>

<!-- Use with variable -->
<div style="height: 100px; background: var(--warming-gradient-global)"></div>

Regional Variables #

For regional data, CSS variables follow the pattern --warming-gradient-{region} (e.g., --warming-gradient-europe-netherlands). Use these for specific regions:

<!-- Use with class -->
<div class="warming-gradient-europe-netherlands" style="height: 100px"></div>

<!-- Use with variable -->
<div style="height: 100px; background: var(--warming-gradient-europe-netherlands)"></div>

Contributing #

Data Structure #

Organize datasets in a folder structure with each dataset in its own subfolder containing a settings.json:

data/
  europe/
    netherlands/
      netherlands.csv
      settings.json
    germany/
      germany.txt
      settings.json
  global/
    global.csv
    settings.json

Generating CSS #

Run the batch processor to generate CSS for all datasets:

python3 generate_all.py data/ -e 2025

This creates:

  • warming-gradient.css - Combined CSS with all gradients
  • settings_log.json - Log of all settings and CSS variable names

CSS Variable Naming #

Each dataset's CSS variable follows the pattern --warming-gradient-{path}, where {path} is the folder path from the data directory with hyphens instead of slashes. For example:

  • data/europe/netherlands/ → --warming-gradient-europe-netherlands
  • data/global/global/ → --warming-gradient-global

Use the variable in your CSS:

.my-element {
  background: var(--warming-gradient-europe-netherlands);
}

Settings #

Each dataset's settings.json supports:

Key Description Default
name CSS name override (without prefix) Folder path (e.g., europe-netherlands)
file Data filename Only .csv/.tsv/.txt file in folder
begin First year 1900 (local) or first year (global)
end Last year Last complete year
scale Color scale (std dev multiple) 3.0 (local)
fixed_scale Color scale (degrees C) 0.9 (global)
read Data reading options (see below) auto-detected
source Data source note (not used) -

Read options:

Key Description Default
header_line Header row number First non-blank line
year_column Year column name/number Column 1
value_column Temperature column Column 2
delimiter Field separator Detected (comma, semicolon, tab)
decimal Decimal mark .
missing Missing value indicators []
type Data type local or global (auto-detected)

Example settings.json:

{
  "begin": 1864,
  "scale": 3.0,
  "read": {
    "header_line": 16,
    "value_column": "year",
    "missing": ["NA"]
  },
  "source": "MeteoSwiss"
}

Command-Line Options #

Flag Description
-s, --scale Color scale in standard deviations
-f, --fixed-scale Color scale in degrees C
-b, --begin Begin year
-e, --end End year
-o, --output-dir Output directory
--css-name Output CSS filename

Command-line flags override settings.json for all datasets.

How It Works #

Color mapping #

  • Blue shades: Below baseline (cooler temperatures)
  • Red shades: Above baseline (warmer temperatures)
  • Gray: Missing data

Reference periods #

  • Baseline (1961-2010): Defines the midpoint where blue transitions to red
  • Standard Deviation (1901-2000): Used to scale color intensity (only if a custom scale is provided)

Scaling modes #

  • Fixed scale: Uses a constant value (default 0.9 for global, 3.0 std dev for local)
  • Calculated scale: Multiplies the calculated standard deviation by your specified value

Read my blog post for more information

License #

Code licensed under MIT license. Please double-check the license for all data yourself.