A JavaScript/TypeScript library for generating EU-compliant energy labels as SVG, in Node.js and in the browser.
import { renderClassArrow } from 'energy-label'
const svgString = renderClassArrow('A', { labelOrientation: 'LEFT' })
import { renderSmartphonesLabel } from 'energy-label'
const svgString = renderSmartphonesLabel()
It is currently available for smartphones and tablets, refrigerating appliances (household fridges and freezers, and wine storage appliances) and class arrows. More templates will be added gradually.
npm install energy-label
See our documentation for more installation methods.
You can generate an energy label and save it as an SVG file using Node.js:
import { EnergyLabel } from 'energy-label'
import fs from 'node:fs'
const label = new EnergyLabel('smartphones')
const svgString = label.toString()
fs.writeFileSync('smartphone-label.svg', svgString)
Missing fields are shown as placeholders (such as XYZ), so you can preview a label before having all its data.
The data fields use the same names and units as the EPREL public API, so a product's data can be passed as it comes. Fields the label doesn't need are ignored.
The EPREL API doesn't allow requests from browsers (CORS), so fetch the data on your server, as in this Node.js example:
import { createEnergyLabelFromEprel } from 'energy-label'
const response = await fetch('https://eprel.ec.europa.eu/api/product/1573269')
const product = await response.json()
const label = createEnergyLabelFromEprel(product)
const svgString = label.toString()
createEnergyLabelFromEprel chooses the label from the product's productGroup, and throws if the library has no label for it. If you already know the product group, createEnergyLabel('refrigerating-appliances', product) does the same.
To fetch EPREL data from the browser, you can host eprel-api-proxy, a small proxy that forwards requests to the EPREL API and adds the CORS headers:
// Requests to the proxy are forwarded to https://eprel.ec.europa.eu/api
const response = await fetch(
'https://your-eprel-proxy.example.com/product/1573269',
)
const product = await response.json()
const label = createEnergyLabelFromEprel(product)
Set CORS_ORIGIN to your site's origin so other sites can't use your proxy from their pages.
The data also decides the variant of the label: a refrigerating appliance with capBottles gets the wine storage label, and a freezer without a fridge compartment shows only the freezer capacity.
The QR code links to the product in EPREL, with the same URL as the official labels. Without eprelRegistrationNumber, it links to the product group page.
Display energy labels directly in web pages using HTML and JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>Simple Energy Label</title>
</head>
<body>
<div id="label-container"></div>
<script type="module">
import {
createEnergyLabel,
appendTo,
} from 'https://esm.sh/energy-label'
const label = createEnergyLabel('smartphones')
const svgString = label.toString()
appendTo(document.getElementById('label-container'), svgString)
</script>
</body>
</html>
You can also download the label directly as an SVG file:
import { download } from 'energy-label'
const svgString = label.toString()
download(svgString)
// Or with a custom filename:
// download(svgString, 'my-energy-label.svg')
toDataURL turns the label into a data URL, to use it as an image source or in CSS. It also works in Node.js:
import { renderClassArrow, toDataURL } from 'energy-label'
const img = document.createElement('img')
img.src = toDataURL(renderClassArrow('A'))
img.alt = 'Energy class A'
Labels are generated synchronously and their markup is deterministic, so they can be rendered on the server and on the client alike, including React Server Components. Use the render functions to bundle only the label you need:
import {
renderSmartphonesLabel,
type SmartphonesAndTabletsData,
} from 'energy-label'
export function SmartphonesLabel(data: Partial<SmartphonesAndTabletsData>) {
// User-provided text is escaped when the label is generated.
return (
<div dangerouslySetInnerHTML={{ __html: renderSmartphonesLabel(data) }} />
)
}
export function ProductPage() {
return (
<SmartphonesLabel
flagOrigin="EU"
supplierOrTrademark="Sultana"
modelIdentifier="92COU8944VK"
energyClass="D"
/>
)
}
For the class arrow alone:
import { renderClassArrow, type EnergyClass } from 'energy-label'
export function ClassArrow({ energyClass }: { energyClass: EnergyClass }) {
return (
<span dangerouslySetInnerHTML={{ __html: renderClassArrow(energyClass) }} />
)
}
The same components work in Preact.
EnergyLabel, createEnergyLabel and createClassArrow choose the template by name, so they bundle all of them. If you only use one label, import its render function instead, which returns the SVG string and bundles only that label:
import { renderClassArrow } from 'energy-label'
const svgString = renderClassArrow('A', { labelOrientation: 'RIGHT' })
| Import | Minified + gzipped |
|---|---|
renderClassArrow |
1 KB |
renderRefrigeratingAppliancesLabel |
7 KB |
renderSmartphonesLabel |
8.3 KB |
createEnergyLabel (all labels) |
10.2 KB |
The class arrow is the lightest, as it has no header with the QR code.
Without a bundler, esm.sh can do the same if you list the exports you use:
import { renderClassArrow } from 'https://esm.sh/energy-label?exports=renderClassArrow'
The regulations use Verdana and Calibri. Labels reference them by name with free fallbacks (DejaVu Sans and Carlito), so they look right on systems without those fonts, such as Linux servers.
You can access the Figma design files here:
👉 Figma Design Sources
Feel free to provide any comments. All kinds of contributions are welcome 🚀.
MIT License © 2025 Marc Mariné