How to Inspect and Control CSS text-spacing-trim for CJK Punctuation in Safari Web Inspector

In internationalized web design and high-end digital publishing, rendering East Asian languages—such as Japanese, Traditional Chinese, and Simplified Chinese—requires specialized typographic handling. In East Asian typographic conventions (Yakumoji), full-width punctuation marks (such as opening brackets 「, closing brackets 」, full-width commas 、, and periods 。) are designed to occupy an entire square em-box. While this uniform width creates balanced body text, it frequently produces unsightly gaps of excessive whitespace when punctuation marks appear at the beginning or end of a line, or when two punctuation marks sit consecutively. Historically, developers relied on complex JavaScript regex manipulations or fragile negative margins to trim punctuation spacing. Standardized in CSS Text Module Level 4 and supported in modern WebKit (Safari 17.4+), the text-spacing-trim property automates punctuation trimming. Safari Web Inspector provides visual tools to audit punctuation glyph bounding boxes and fine-tune CJK typography.

Understanding Punctuation Kerning and text-spacing-trim

The text-spacing-trim property instructs the browser’s typographic shaping engine to trim the internal blank space (advance width) built into full-width punctuation glyphs. Understanding its primary values ensures proper implementation:

  • normal: The default value. Applies standard typographical trimming rules. Trims opening punctuation at the beginning of a line, trims closing punctuation at the end of a line, and compresses consecutive adjacent punctuation marks so that two half-width spaces merge into a single natural gap.
  • trim-start: Specifically trims the internal whitespace preceding full-width opening punctuation marks when they appear at the start of a line or after a line break, ensuring characters align flush with the left (or vertical top) margin.
  • space-all: Disables automated punctuation trimming entirely. Preserves the full square em-box width for every punctuation mark, maintaining strict monospace grid alignment common in traditional East Asian technical printing.
  • space-first: Similar to normal, but preserves the full-width spacing for opening punctuation at the very beginning of the first line of a paragraph while trimming subsequent line starts.

Configuring Safari Web Inspector for CJK Typography Auditing

To audit punctuation trimming behaviour in Safari Web Inspector, right-click the target CJK text block and select Inspect Element (or press Option + Command + I).

To inspect rendering on an iPad or iPhone, connect the device to your Mac, open desktop Safari, and select your mobile device from the Develop menu.

Ensure that your document or text container explicitly declares the appropriate language attribute in its HTML tag to enable WebKit’s script-specific shaping algorithms:

<html lang="ja"> <!-- Enables Japanese OpenType shaper features -->

Inspecting and Testing text-spacing-trim in Web Inspector

Use the Styles panel in Web Inspector to evaluate how punctuation trimming impacts visual alignment:

  1. In the DOM tree, select the container holding Japanese or Chinese text containing opening brackets or full-width periods.
  2. In the right sidebar, open the Styles panel.
  3. Apply the text-spacing-trim property within the target rule:
    .article-heading {
      font-family: -apple-system, "Hiragino Sans", "PingFang SC", sans-serif;
      text-spacing-trim: normal;
      font-size: 1.5rem;
      line-height: 1.6;
    }
  4. Toggle between text-spacing-trim: normal; and text-spacing-trim: space-all;. Observe how setting space-all pushes the opening quotation mark away from the margin, whereas normal or trim-start pulls the bracket flush against the container edge.
  5. Switch to the Computed tab and search for text-spacing-trim to verify that WebKit successfully computed the value without cascading conflicts.

Debugging Consecutive Punctuation Compression

A classic typographic defect in unmanaged East Asian layouts occurs when a quotation mark immediately follows a comma or period (e.g. 。」). Without automated spacing trim, the two full-width glyphs create an unnatural full-em gap between words.

To inspect how WebKit compresses adjacent punctuation:

  1. In Web Inspector, locate an element containing adjacent punctuation pairs:
    <p class="cjk-quote">彼は「成功した。」と言いました。</p>
  2. Open the Fonts panel in Web Inspector and inspect the active OpenType layout features.
  3. Apply text-spacing-trim: normal;. WebKit automatically engages OpenType halt (Alternate Half Widths) or chws (Contextual Half-width Spacing) font tables, reducing the two adjacent spaces into a balanced typographic transition.

Auditing Vertical Typography with text-spacing-trim

Punctuation spacing issues become even more pronounced in vertical writing modes (writing-mode: vertical-rl), where top and bottom punctuation margins must align with the vertical header boundary.

Inspect vertical text spacing by pairing text-spacing-trim with vertical layout rules:

.vertical-callout {
  writing-mode: vertical-rl;
  text-orientation: upright;
  text-spacing-trim: trim-start;
  font-family: "Hiragino Mincho ProN", serif;
}

In Safari Web Inspector, select the vertical container and toggle text-spacing-trim. Notice that with trim-start active, top-line brackets align perfectly with the top edge of the column, eliminating uneven vertical drop offsets.

Troubleshooting Font and Compatibility Edge Cases

When implementing text-spacing-trim, keep these technical details in mind:

  • Font Metric Table Requirements: text-spacing-trim relies on OpenType chws (Contextual Half-width Spacing) or halt feature tables embedded in the font. System fonts like Apple’s Hiragino Sans and PingFang feature complete table coverage. If custom third-party web fonts lack these tables, WebKit synthesizes geometric trimming based on glyph bounding boxes.
  • Browser Feature Detection: To provide progressive enhancement for older browsers that do not yet support the CSS Text 4 property, use the @supports rule:
    @supports (text-spacing-trim: normal) {
      .cjk-text {
        text-spacing-trim: normal;
      }
    }
  • Interference from letter-spacing: If an author declares manual CSS letter-spacing on CJK text, excessive tracking will artificially reintroduce gaps between trimmed punctuation marks. Keep letter-spacing: normal or use relative tracking carefully.

By leveraging text-spacing-trim in Safari Web Inspector, front-end engineers ensure clean, professional, and culturally compliant East Asian typography across macOS, iOS, and iPadOS devices.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.