JsonCut

Text fitting in templates: long copy, fixed frames

Product names outgrow their frames. A measured contract for font steps, line caps and truncation rules, so a bulk render never ships cut-off text.

Abstract geometric illustration for Text fitting in templates: long copy, fixed frames

A campaign card is a design decision until a 54-character product name arrives in a slot built for 16. This is a practical method for deciding which text may shrink, which may wrap and which must be truncated, with measurements you can repeat in your own font.

The slot that was designed for one sentence

Every template eventually meets the string nobody typed in the design file. A product card is approved with "Jetzt erhältlich" in a two-line headline slot. In production the feed sends "Espresso-Maschine Barista Pro, Edelstahl, 1,8 Liter" — 51 characters where 16 were expected. The render does not fail. It produces a beautiful image in which the last line reads "Liter", alone, under a price that no longer belongs to it.

Two reactions are common: design for the longest possible string, which flattens the hierarchy for every median case; or let the box auto-shrink until something fits, which changes the hierarchy just as silently. A third option is a contract: named slots, measured capacity per slot, and one explicit rule for what happens when a string exceeds it.

Overflow is structural, not sloppy. In a fixed layout every layer except text has a fixed height. Text is the only layer whose geometry depends on its content, and in a bulk run the content arrives after the design was approved. That asymmetry is why text, not the image, is where automated renders break.

Abstract dark artwork with soft green and violet gradient blobs behind a fine grid

What a line actually costs, measured

Character counts are the usual proxy, and they are unreliable. The reason is proportional fonts: an "i" is not a "W". To replace the intuition with numbers, I measured two common sans-serifs with Pillow 13.0.0 — Liberation Sans, which shares Arial's metrics, and DejaVu Sans — in a 1000-pixel-wide text box with greedy word wrapping at the spaces, at 72 px type.

SampleCharsWidth at 72 px (regular)Lines at 72 px (bold)Avg. advance
Jetzt erhältlich16460 px10.40 em
Espresso-Maschine Barista Pro, Edelstahl, 1,8 Liter511644 px20.45 em
Ultralight Performance Running Jacket, Men, Storm Blue541808 px30.46 em

The average advance lands around 0.45 em per character for mixed Latin text, so a 1000 px line at 72 px holds roughly 31 characters. But the measured first lines of those wrapped samples held 17 to 25 characters, because a line breaks at a space and the remainder of the last word is lost to the box. A character budget taken from the average will therefore be about a third too generous.

Font choice moves the number by more than most margins allow. The same strings measured 13.0% and 12.1% wider in DejaVu Sans than in the Arial-metric font at the same size. Swap a brand font, and a 10% safety margin disappears. This is the practical reason not to hard-code "about 30 characters per line" in a content guideline — measure in the font that renders.

The fit ladder: discrete steps, measured

If one size cannot serve both a 16-character and a 54-character string, the next question is which sizes may appear. Continuous auto-fit produces 71, 68, 63 px and a design that looks accidental at every value. A short ladder — 72, 64, 56, 48, 40 px — keeps every state looking intentional at the cost of a few pixels of unused space.

The largest size at which each sample still fits a two-line slot in the same 1000 px box (bold):

SampleCharsFits 2 lines up toLadder stepSize cutFits 3 lines up to
Jetzt erhältlich16200 px+72 px0%200 px+
Espresso-Maschine Barista Pro, Edelstahl, 1,8 Liter5176 px72 px0%113 px
Autumn Sale: 40% off everything until Sunday midnight5463 px56 px22%110 px
Ultralight Performance Running Jacket, Men, Storm Blue5466 px64 px11%92 px
Kompaktkamera mit 24-Megapixel-Sensor und 3-Zoll-Display5653 px48 px33%105 px

Two lessons sit in that table. First, a three-line slot absorbs every sample at the approved size — the line cap, not the font size, is the real budget. Second, the worst case costs a third of the type size. At 48 px the card still reads well; the headline is simply no longer the loudest element, which is a design decision that should be made once, deliberately, rather than per row by an algorithm.

If the design cannot afford a 33% drop, the slot cannot accept 56 characters. That is a copy rule, not a rendering bug, and it belongs in the template documentation next to the approved layout.

A line cap beats an auto-fit for most slots

Auto-fit has a second, quieter cost: it rewards whoever writes the worst string. Every overlong product name is silently absorbed, so nobody shortens the feed data, and the layout slowly drifts to the size of its worst input. A line cap with an explicit fallback keeps the design stable and pushes the decision back to the data owner.

SlotLinesShrink allowedOverflow rule
Headline2Yes, ladder down to 48 pxTruncate at word boundary, keep a 6-character margin
Product name2Yes, ladder down to 56 pxEllipsis after the differentiating word, never mid-word
Price and unit1NoReject the row; a smaller price changes the offer
Badge / kicker1NoDrop the badge; it is decoration, not information
Legal or source line3Yes, down to 32 pxDrop optional clauses, never ellipsize a legal statement

The price row deserves the strongest rule. Shrinking a price to fit does not just look worse; it changes what the viewer compares. If the formatted number cannot fit, the row is wrong — and formatted numbers grow, as the separator and symbol rules in number and currency formatting in automated renders show: 1234.56 becomes 1.234,56 € with a non-breaking space before the symbol.

Wrapping rules that do the quiet work

Before any fitting logic, the wrapping engine should be told what to do with the string. Five CSS properties cover most of it, with caveats worth knowing in a render pipeline — the reference for text-wrap and overflow-wrap is short enough to read in full.

RuleWhat it doesCaveat
text-wrap: balanceEvens out line lengths in short blocks such as headingsLimited to short blocks: six lines or fewer in Chromium, ten in Firefox
text-wrap: prettyPrefers better layout over speed, for body copySlower algorithm; rarely worth it for a single headline in an image
overflow-wrap: anywhere / break-wordBreaks an unbreakable word instead of letting it overflowanywhere affects min-content sizing, break-word does not
hyphens: autoHyphenates long compounds at language-specific pointsRequires a lang attribute and an available dictionary
line-clampCaps lines and appends an ellipsisNot Baseline; needs overflow: hidden, and legacy support needs the -webkit-box-oriented setup

Hyphenation is the rule most often assumed and least often verified. German compounds are a stress test: Geschwindigkeitsbegrenzung measures 1020 px at 72 px in the same bold font — one word, wider than the entire 1000 px box. Without a dictionary and a correct lang attribute, that word does not wrap at all; it overflows, or it is broken at an arbitrary character with overflow-wrap. In a localized template, the same headline slot therefore needs a per-language capacity test, not one global character limit. If the same artboard is reused in 1:1 and 9:16, the slot width changes with the crop and the capacity must be measured per aspect, as described in aspect ratio safe areas.

Where the platform stops caring

A template engine can validate types and constraints; it cannot know your font. JsonCut templates expose typed variables — string, number, boolean, color, image, video, audio, sanitized HTML and a bounded flat string array. Numeric variables may declare a finite min, max, a positive step and a unit; those constraints are not accepted on non-number variables. In other words: a price can be bounded at the input contract, a headline cannot.

The remaining limits are structural rather than typographic. A repeat list carries at most 100 strings of at most 1000 characters each. Bulk batches hold up to 50 rows on Hobby, 250 on Pro and 500 on Business, and CSV bodies up to 2,000,000 characters. Every row is validated against the pinned template version before queueing, and invalid rows are reported without stopping valid ones — but a 900-character headline is a valid string. The contract in template input design decides what the field is for; nothing in the platform decides how many lines it needs.

So the fitting step moves upstream. Either the data layer derives a display string plus a length class, or the editorial process rejects the row. Both are cheaper than discovering the problem in a queue of 250 renders.

// Browser or headless renderer: one canvas, the real font, greedy wrap.
const ctx = document.createElement("canvas").getContext("2d");
const STEPS = [72, 64, 56, 48, 40];

function fits(text, size, width, maxLines) {
  ctx.font = `700 ${size}px "Inter", sans-serif`;
  const words = text.split(/\s+/);
  let line = words[0], lines = 1;
  for (const word of words.slice(1)) {
    if (ctx.measureText(`${line} ${word}`).width <= width) line += ` ${word}`;
    else { lines += 1; line = word; }
  }
  return lines <= maxLines;
}

function fitSize(text, width, maxLines) {
  for (const size of STEPS) if (fits(text, size, width, maxLines)) return size;
  return null; // caller truncates or rejects - never guesses
}

The function returns null on purpose. A fitter that always returns a size will eventually return 12 px and call it success.

A layout contract you can hand to a builder

Written down, the contract is short enough to paste into a template ticket. It carries the capacity numbers, the fallback and the owner, so the next bulk run does not renegotiate them.

FieldTypeMax charsLinesSize ruleFallback
headlinestring422Ladder 72 → 48Truncate at word, keep 6-char margin
sublinestring702Fixed 56Ellipsis
product_namestring402Ladder 64 → 56Ellipsis after the differentiating word
price_displaystring121Fixed 72Reject row, report to data owner
badgestring121Fixed 32, uppercaseHide layer
legal_linestring1603Fixed 32Drop optional clauses

Two fields in that table are worth arguing about before the build. price_display is a formatted string whose length depends on locale and symbol style, so it should come from the same code path that renders it, never typed. product_name usually receives a marketplace title with three qualifiers appended, so its ellipsis rule needs a definition of "differentiating word" — typically brand plus model, cut after the model number.

Test with worst-case strings, not with real ones

A test set built from current data passes by construction. Build it from the extremes instead:

  • The longest product name in the catalogue, plus 20% of padding.
  • A compound word from each localization, in its native script.
  • An all-caps variant: the same 53-character sale line measured 21% wider in caps.
  • A formatted price at the longest locale variant and the widest currency symbol.
  • A string with a non-breaking space, a soft hyphen and an emoji, since all three change line breaking.

Render the ten worst rows as a contact sheet and look at them together. A single card hides an orphaned line; ten side by side make the pattern obvious. This is the same review step that keeps bad renders out of a queue in the render review gate, applied to text capacity rather than to colour or crop.

Checklist before the next bulk run

  • Every text slot has a measured character capacity in the font that actually renders.
  • Each slot has a line cap, a size rule and a fallback written down.
  • The fitter returns "no fit" instead of an arbitrarily small size.
  • Prices never shrink; they are rejected and reported.
  • Hyphenation is verified in each localized language, with lang set.
  • The ten worst-case strings were rendered and reviewed as a set.

None of this makes a template immune to bad data. It makes the failure visible at the point where someone can still fix it — in the pipeline, before 250 variant files exist that nobody has time to re-render.

Sources

JSONCut, "Typed templates and bulk rendering" — https://jsoncut.com/docs/templates/ (retrieved 2026-12-02) JSONCut, "Variables and reusable templates" — https://jsoncut.com/docs/create/variables-and-templates/ (retrieved 2026-12-02) MDN Web Docs, "text-wrap CSS property" — https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap (retrieved 2026-12-02) MDN Web Docs, "overflow-wrap CSS property" — https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap (retrieved 2026-12-02) MDN Web Docs, "hyphens CSS property" — https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens (retrieved 2026-12-02) MDN Web Docs, "line-clamp CSS property" — https://developer.mozilla.org/en-US/docs/Web/CSS/line-clamp (retrieved 2026-12-02) Own measurement: Pillow 13.0.0, Liberation Sans and DejaVu Sans, 1000 px text box, greedy word wrap, 72 px type (2026-12-02)

Your next post is one sentence away.Start free, no editing skills needed.