Home / Part to Whole / Marimekko Chart
Marimekko Chart in HTML, CSS and JavaScript
A Marimekko chart, often called a Mekko chart, is a 100% stacked bar chart where each column has a different width. This free template draws one with plain SVG and vanilla JavaScript, no chart library. The example shows e-bike market share by region and brand.
What is a marimekko chart?
A Marimekko chart, often called a Mekko chart, is a 100% stacked bar chart where each column has a different width. The width shows how big each group is, and the colors inside show the shares within it.
It answers two questions in one picture: which markets are biggest, and who leads in each one. Consultants and market researchers use it to show market share by region or segment.
At a glance
- Best for
- Market share across segments of different size
- Data you need
- A size for each group and shares inside each group
- Skip it when
- Audiences who have never seen one. Add a short guide.
- Made with
- HTML, CSS and vanilla JavaScript. No library.
When to use a marimekko chart
- Market share by region and brand
- Sales by channel and product
- Customers by age group and plan
- Budget by department and type of cost
When to pick another chart
- 100% Stacked Bar Chart: all groups are the same size or size does not matter
- Treemap: you care more about the size of each piece than the share
What you get in this template
- Column widths set by how many bikes each region bought
- Brand shares stacked to 100% inside each column
- Percent labels inside every piece that has room
- Tooltips with the share, the number of bikes and the share of all sales
- Pieces grow into place on load
- Keyboard support and a data table
How the code works
Here is a short version of the idea behind this marimekko chart. The full file adds the axis, labels, tooltips, sorting and resizing on top of it.
const regions = [['North', 42, [38, 27, 21, 14]], ['South', 30, [22, 35, 25, 18]]];
const colors = ['#e76f51', '#2a9d8f', '#e9c46a', '#9aa5b5'];
const total = regions.reduce((a, r) => a + r[1], 0);
let x = 40;
regions.forEach(([name, size, shares]) => {
const w = size / total * 520;
let y = 280;
shares.forEach((pct, i) => {
const h = pct / 100 * 260;
drawRect(x, y - h, w - 3, h - 1, colors[i]);
y -= h;
});
drawText(x + w / 2, 298, name, 'middle');
x += w;
});The example uses four tiny helpers that create SVG shapes. Put them above the code and it runs as is.
const svg = document.querySelector('svg');
function make(tag, attrs) {
const n = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (const k in attrs) n.setAttribute(k, attrs[k]);
svg.appendChild(n);
return n;
}
function drawRect(x, y, width, height, fill) { return make('rect', { x, y, width, height, fill }); }
function drawCircle(cx, cy, r, fill) { return make('circle', { cx, cy, r, fill }); }
function drawLine(x1, y1, x2, y2, stroke, width, dash) {
return make('line', { x1, y1, x2, y2, stroke, 'stroke-width': width || 1, 'stroke-dasharray': dash || 'none' });
}
function drawText(x, y, str, anchor) {
const t = make('text', { x, y, 'text-anchor': anchor || 'start' });
t.textContent = str;
return t;
}How to add it to your website
- Download the file. Click Download HTML file above. You get one file called marimekko-chart.html with everything inside.
- Change the data. Open the file in any code editor and find the DATA list near the bottom. Replace the names and numbers with your own.
- Change the colors and text. Colors are at the top of the style tag. The title, subtitle and main point are plain HTML near the top of the body.
- Put it online. Upload the file to any host, such as GitHub Pages, Netlify or your own server, or paste it into your site. There is no build step.
Questions people ask
What is a Marimekko chart?
It is a stacked bar chart where each bar has a different width. Width shows the size of each group and the stacked colors show the shares inside it.
Why is it called a Marimekko chart?
It is named after the Finnish design company Marimekko, because the blocks of color look like their bold printed fabrics.
What is the difference between a Marimekko chart and a mosaic plot?
They are very close. Mosaic plot is the name used in statistics, often for counts in a table. Marimekko is the business name, usually for market share.
How do I read a Marimekko chart?
Read the widths first to see which groups are biggest, then read the colors inside each column to see who leads in that group.
More part to whole

021. Pie Chart
Example: how customers paid at a cafe
022. Donut Chart
Example: workouts logged by members of a fitness app
023. Semi Donut Chart
Example: a fundraising appeal and the money still needed
024. Treemap
Example: bookshop sales by section and genre
025. Sunburst Chart
Example: where a city sends its household waste
026. Waffle Chart
Example: how 100 new customers found a furniture shop
028. Funnel Chart
Example: shoppers moving from first visit to purchase in an online shop
029. Icicle Chart
Example: what is filling up a laptop drive