W3docs

String Functions

String Length Calculator

Count the number of characters in a string — useful for size budgets in CSS, JavaScript, or meta descriptions.

About counting string length

This tool counts the number of characters in whatever text you paste, including spaces, punctuation, and line breaks. It counts by Unicode code point, so an accented letter like “é” counts as one character and an emoji like “👍” counts as one — which is often not what a programming language’s built-in length will tell you.

Character counts come up constantly in web work: a meta description should sit around 150–160 characters before search engines truncate it, a tweet has its own limit, a database VARCHAR column has a maximum, and design copy has to fit a fixed space. Knowing the exact count saves you a round-trip of guess-and-check.

Be aware that “length” has three different meanings depending on what’s counting. The number of visible characters (code points), the number of UTF-16 code units (what JavaScript’s String.length returns), and the number of bytes (what a UTF-8 database or network payload measures) can all differ for the same string once you leave plain ASCII.

Three ways to measure length in JavaScript

For the string "café👍", each method gives a different answer — and each is correct for a different question:

UTF-16 code units — String.lengthjs
"café👍".length; // 6
// "café" is 4 units, the 👍 emoji is a surrogate pair = 2 units

This is the fast built-in, but it over-counts any character outside the Basic Multilingual Plane (most emoji, some CJK).

Characters (code points) — what this tool countsjs
Array.from("café👍").length; // 5
[..."café👍"].length;        // 5 (same thing)

Spreading or Array.from splits by code point, so the emoji counts as one character — the count a human expects.

Bytes — what UTF-8 storage and payloads usejs
new TextEncoder().encode("café👍").length; // 8
// "caf" = 3 bytes, "é" = 2 bytes, "👍" = 4 bytes

Use this when you’re sizing a database column, a cookie, or a network request rather than counting visible characters.

Frequently asked questions

Does the count include spaces and line breaks?

Yes. Every character you paste is counted, including spaces, tabs, punctuation, and newlines — nothing is stripped before counting.

Why does my emoji sometimes count as 2 elsewhere?

JavaScript’s String.length counts UTF-16 code units, and most emoji are stored as a surrogate pair (two units). This tool counts by code point, so an emoji counts as a single character.

What’s the difference between characters and bytes?

A character is one visible symbol; a byte is one unit of storage. In UTF-8, ASCII characters are 1 byte each, but accented letters take 2 and many emoji take 4 — so byte length can exceed character length.

How long should a meta description be?

Aim for roughly 150–160 characters. Google truncates longer descriptions in search results, so keeping under that ceiling ensures your full snippet shows.