How to use Datatype in web projects, frameworks, and static site generators
Get Datatype.woff2 from the latest release and add it to your project.
Add this CSS to your stylesheet:
@font-face {
font-family: 'Datatype';
src: url('/fonts/Datatype.woff2') format('woff2');
font-weight: 100 900; /* Variable weight axis */
font-stretch: 0% 100%; /* Variable width axis */
font-display: swap;
}
Style elements that contain chart syntax:
.chart {
font-family: 'Datatype', sans-serif;
font-feature-settings: 'liga' 1, 'calt' 1;
font-variant-ligatures: common-ligatures contextual;
letter-spacing: 0;
}
<p>
Sales <span class="chart">{l:20,45,60,55,80,95}</span> are up this quarter.
</p>
Using next/font/local (Recommended)
// app/layout.js or pages/_app.js
import localFont from 'next/font/local'
const datatype = localFont({
src: './fonts/Datatype.woff2',
variable: '--font-datatype',
weight: '100 900',
stretch: '0% 100%',
display: 'swap',
})
export default function RootLayout({ children }) {
return (
<html className={datatype.variable}>
<body>{children}</body>
</html>
)
}
CSS:
.chart {
font-family: var(--font-datatype), sans-serif;
font-feature-settings: 'liga' 1, 'calt' 1;
}
Place Datatype.woff2 in public/fonts/, then add to your layout:
---
// src/layouts/Layout.astro
---
<style is:global>
@font-face {
font-family: 'Datatype';
src: url('/fonts/Datatype.woff2') format('woff2');
font-weight: 100 900;
font-stretch: 0% 100%;
font-display: swap;
}
.chart {
font-family: 'Datatype', sans-serif;
font-feature-settings: 'liga' 1, 'calt' 1;
}
</style>
Place font in public/fonts/, then add to your CSS:
/* styles.css or App.css */
@font-face {
font-family: 'Datatype';
src: url('/fonts/Datatype.woff2') format('woff2');
font-weight: 100 900;
font-stretch: 0% 100%;
font-display: swap;
}
.chart {
font-family: 'Datatype', sans-serif;
font-feature-settings: 'liga' 1, 'calt' 1;
}
Place font in src/fonts/ and add passthrough copy:
// .eleventy.js
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/fonts");
};
Then add CSS to your stylesheet.
Place font in static/fonts/, then add to app.css:
@font-face {
font-family: 'Datatype';
src: url('/fonts/Datatype.woff2') format('woff2');
font-weight: 100 900;
font-stretch: 0% 100%;
font-display: swap;
}
Datatype has two variable axes you can control:
| Axis | Tag | Range | Default | Effect |
|---|---|---|---|---|
| Width | wdth |
0–100 | 50 | Controls spacing between chart elements |
| Weight | wght |
100–900 | 400 | Controls line thickness |
Method 1: Standard properties (Recommended)
.chart {
font-family: 'Datatype', sans-serif;
font-weight: 600; /* wght axis */
font-stretch: 75%; /* wdth axis */
}
Method 2: font-variation-settings
.chart {
font-family: 'Datatype', sans-serif;
font-variation-settings: 'wdth' 75, 'wght' 600;
}
Safari Note: When using font-variation-settings, include ALL axes in a single declaration. Safari doesn't merge separate axis declarations like Chrome/Firefox do.
{b:value,value,value,...}
{b:15,45,80,30,60,90}{l:value,value,value,...}
{l:10,40,25,70,50,90}{p:value}
{p:75}font-display: swap to prevent invisible text while loading<link rel="preload" href="/fonts/Datatype.woff2" as="font" type="font/woff2" crossorigin>Datatype requires OpenType ligature features to work. Always include:
font-feature-settings: 'liga' 1, 'calt' 1;
font-variant-ligatures: common-ligatures contextual;
Set letter-spacing: 0 to prevent gaps in charts. Letter spacing breaks the precise glyph alignment.
Causes:
font-feature-settingsSolution: Set letter-spacing: 0
Solution: Use font-weight and font-stretch properties, OR include all axes in a single font-variation-settings declaration.
Want to auto-wrap chart syntax in your framework or CMS? Here's how:
Match chart syntax with this regex:
/\{[blp]:\d+(?:,\d+)*\}/g
Wrap matches in a span with the font applied:
<span class="datatype">{l:20,40,60}</span>
function renderDatatype(text) {
const pattern = /\{[blp]:\d+(?:,\d+)*\}/g;
return text.replace(pattern, match =>
`<span class="datatype">${match}</span>`
);
}
// Usage
const input = "Sales {l:20,45,60,55,80} are up.";
const output = renderDatatype(input);
document.getElementById('output').innerHTML = output;
function datatypePlugin(md) {
const pattern = /\{[blp]:\d+(?:,\d+)*\}/g;
md.core.ruler.push('datatype', state => {
for (const token of state.tokens) {
if (token.type !== 'inline') continue;
for (const child of token.children) {
if (child.type === 'text' && pattern.test(child.content)) {
// Wrap chart syntax in HTML
child.content = child.content.replace(pattern,
match => `<span class="datatype">${match}</span>`
);
child.type = 'html_inline';
}
}
}
});
}
// Usage
const md = require('markdown-it')();
md.use(datatypePlugin);
function Chart({ children }) {
const pattern = /\{[blp]:\d+(?:,\d+)*\}/g;
const parts = children.split(pattern);
const matches = children.match(pattern) || [];
return (
<>
{parts.map((text, i) => (
<React.Fragment key={i}>
{text}
{matches[i] && (
<span className="datatype">{matches[i]}</span>
)}
</React.Fragment>
))}
</>
);
}
// Usage
<p>
<Chart>Sales {'{l:20,45,60,55,80}'} are up.</Chart>
</p>
Note: In JSX/MDX, curly braces are special syntax. You'll need to escape chart expressions as strings or use a wrapper component.