W3docs

String Functions

String Length Calculator Online

Count characters, Unicode code points, UTF-16 units, UTF-8 bytes, words and lines as you type — useful for size budgets in CSS, JavaScript, or meta descriptions.

Live breakdown

Characters
0
Code points
0
UTF-16 units
0
UTF-8 bytes
0
Words
0
Lines
0

About counting string length

This online string length calculator updates as you type and shows characters, Unicode code points, UTF-16 code units, UTF-8 bytes, words and lines side by side. Spaces, punctuation, and line breaks are all counted. “Characters” means what a person sees as one symbol, so an accented letter like “é” and an emoji like “👍” each count 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).

Code points — the “Code points” figure in this tooljs
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’s Characters figure counts what you see, so an emoji counts as a single character (its UTF-16 units figure matches String.length).

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.