Home / SEO and Site Tools / Meta Tag Generator

Meta Tag Generator in JavaScript, Free with Live Demo

Free meta tag generator in plain JavaScript. Write your title and description with live length checks, see a search result and social card preview, and copy the finished meta tags.

Open live demoDownload HTML fileView code on GitHub
Meta Tag Generator JavaScript project: a form that writes your title, description and social tags with live search and share previews

Runs on: Canvas text measuring. Works in all modern browsers.

What is the Meta Tag Generator?

A meta tag writer. Type a title, description, URL and share image, and see a search result preview and a social share card update live.

Length bars measure the text in pixels, like search engines do, and warn you before a title or description gets cut off. The finished tags are ready to copy.

Good for

  • Launching new pages
  • Fixing pages with poor click rates
  • Checking client sites
  • Teaching the basics of SEO

What this project does

How it works

  1. Measure in pixelsSearch engines cut titles by width, not letters. Canvas measureText measures the text in the same font size to warn you before it gets cut.
  2. Preview both placesThe search result and the share card update as you type, using the same truncation rules.
  3. Write clean tagsValues are escaped for HTML, the image tag only appears when there is an image, and the robots tag follows your noindex choice.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

const ctx = document.createElement("canvas").getContext("2d");
ctx.font = "20px Arial";
const tooLong = ctx.measureText(title).width > 580;   // about where results cut off

const tags = `
<title>${title}</title>
<meta name="description" content="${description}">
<meta property="og:title" content="${title}">
<meta property="og:image" content="${image}">
<meta name="twitter:card" content="summary_large_image">`;

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

How long should a title be?

Aim for about 50 to 60 characters. Wide letters take more room, which is why the tool measures pixels.

Does the meta description affect ranking?

Not directly, but a clear description gets more clicks, and that matters.

What size should the share image be?

1200 by 630 pixels works well on every major platform.

More SEO and Site Tools projects