NBSP and narrow spaces: preserve typography, normalize data deliberately

NO-BREAK SPACE U+00A0 looks much like U+0020 but prevents a line break. NARROW NO-BREAK SPACE U+202F is narrower and appears in the typography of several languages. Both are useful in prose, while a numeric parser, CSV import or exact comparison may not treat them as an ordinary ASCII space.
Same appearance, different data
A label such as 10 kg keeps the number and unit together, which is sensible on a web page. The string is not equal to 10 kg containing U+0020, and a parser can reject 1 234 as a number. The problem is not that NBSP is “bad”; a presentation character has reached a field with a different contract.
Separate storage from presentation
Preserve appropriate typography in articles. For quantities, prices and identifiers, define a machine format—perhaps digits plus a decimal point and no thousands separator. Normalize when data enters the system, then format it for display at the boundary. This makes the rule testable and independent of the user’s copy source.
There is more than one space
Besides U+0020, U+00A0 and U+202F, Unicode includes THIN SPACE U+2009, FIGURE SPACE U+2007 and other typographic widths. JavaScript \s, trimming functions and individual parsers do not necessarily use the same sets. Read the actual API or format specification rather than assuming every visual space is interchangeable.
A safe normalization plan
- Preserve the raw value.
- Reveal spaces and record their code points.
- Classify the field as prose or structured numeric data.
- For a numeric field, remove permitted grouping separators or map specific U+00A0/U+202F according to the contract.
- Parse strictly and validate the resulting range.
Do not strip every space from addresses, names or sentences. Even numeric punctuation depends on locale: 1,234 can represent different values under different conventions.
CSV and spreadsheet checks
Sample rows from every source before converting a column. If NBSP is only a thousands separator, transform the column to a numeric type and compare totals before and after. If the same column contains comments, split the data model instead of applying an aggressive replacement to the full file. Log how many cells changed.
JavaScript example
const label = "10\u00A0kg";
label === "10 kg"; // false
label.replace(/[\u00A0\u202F]/g, " "); // 10 kg
Number("1 234"); // NaNThe replacement is suitable for the display label. For a numeric field, remove only documented grouping marks, then verify the entire remaining string against the numeric grammar.
A numeric-column test
Prepare values using U+0020, U+00A0, U+202F and no grouping mark. Apply the same rule, then compare parsed values, totals and rejected rows. The outcome must match the agreed locale rather than merely look plausible. During import, retain the raw string beside the normalized number so disputed transformations can be investigated.
Sources and specifications
- Unicode chart: U+00A0 NO-BREAK SPACE
- Unicode chart: U+202F NARROW NO-BREAK SPACE
- WHATWG Infra: ASCII whitespace