Home / Dashboard Widgets / Word Cloud

Word Cloud in HTML, CSS and JavaScript

A word cloud shows a set of words where the size of each word matches how often it appears. This free template draws one with plain SVG and vanilla JavaScript, no chart library. The example shows words guests use in hotel reviews.

Open live demoDownload HTML fileView code on GitHub
Word Cloud made with HTML and JavaScript showing words guests use in hotel reviews

What is a word cloud?

A word cloud shows a set of words where the size of each word matches how often it appears. The biggest words are the ones people use most.

It is a quick, friendly way to sum up a pile of text like reviews or survey answers. Coloring words by meaning, like praise and complaints, turns it from decoration into something you can act on.

At a glance

Best for
A quick feel for common words in text
Data you need
A list of words with a count for each
Skip it when
Exact comparisons. Use a bar chart.
Made with
HTML, CSS and vanilla JavaScript. No library.

When to use a word cloud

  • Customer reviews and survey answers
  • Common search terms on your site
  • Topics in comments or support tickets
  • Themes from workshops and interviews

When to pick another chart

What you get in this template

How the code works

Here is a short version of the idea behind this word cloud. The full file adds the axis, labels, tooltips, sorting and resizing on top of it.

const words = [['friendly', 142], ['clean', 128], ['location', 118], ['small', 48], ['noisy', 41]];
const ctx = document.createElement('canvas').getContext('2d');
const placed = [], cx = 300, cy = 150;

words.forEach(([word, count]) => {
  const size = 14 + Math.sqrt(count) * 3; ctx.font = size + 'px sans-serif';
  const w = ctx.measureText(word).width, h = size;
  for (let t = 0; t < 2000; t++) {
    const x = cx + t * 0.9 * Math.cos(t * 0.35) - w / 2, y = cy + t * 0.6 * Math.sin(t * 0.35);
    if (placed.some(p => x < p.x + p.w && x + w > p.x && y - h < p.y && y > p.y - p.h)) continue;
    placed.push({ x, y, w, h });
    make('text', { x, y, 'font-size': size }).textContent = word;
    break;
  }
});

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

  1. Download the file. Click Download HTML file above. You get one file called word-cloud.html with everything inside.
  2. 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.
  3. 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.
  4. 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 word cloud?

A word cloud is a picture of words where each word is sized by how often it appears in a text. It is also called a tag cloud.

How does a word cloud place the words?

It starts at the center and moves outward along a spiral, placing each word at the first spot where it does not overlap any word already placed. Bigger words go first.

Are word clouds useful?

For a quick overview, yes. They are not good for exact comparisons, so pair them with a bar chart of the top words when numbers matter.

Should I remove common words?

Yes. Words like the, and or very should be dropped before counting, or they will crowd out the words that tell you something.

More dashboard widgets