PDFPipe

Who the document is between / Contact details block

A contact block where the long email address does not break the layout

Phone, email, reference number and website, usually set small under a name or in a footer, and usually the block that overflows first.

Why this block is harder than it looks

Contact details are short strings with one long exception, and the exception is always an email address or a URL. Those cannot be hyphenated at arbitrary points without changing what they mean, so a browser leaves them intact and lets them overflow the box. In a narrow column, one address at a real domain is enough to push past the edge, and because the block is set small nobody notices until a customer with a long domain appears. The second problem is that these blocks are usually a list of labelled pairs, and labelled pairs are where inconsistent alignment shows up most.

The decisions that make it work

Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.

  • Set overflow-wrap: anywhere on the values so a long address breaks rather than overflowing. Breaking an email address across two lines is ugly and legible, overflowing is neither.
  • Do not set hyphens: auto on this block. A hyphen inserted into an email address changes it, and a reader retyping it will include the hyphen.
  • Use a two-column grid for the label and the value rather than a table or a run of spans, so the values start at the same x position on every row.
  • Keep labels short enough that the label column can be narrow, and set them in a lighter weight or smaller size so the values read first.
  • Do not turn addresses into links styled with an underline in a document that will be printed. The underline collides with descenders at small sizes and buys nothing on paper.
  • Give the block a real minimum size. Contact details set at 7pt to make them fit are contact details nobody will use.

The fragment

Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.

html
<dl class="contact">
  <dt>Reference</dt><dd>WH-2026-0418</dd>
  <dt>Phone</dt><dd>+44 114 496 0022</dd>
  <dt>Email</dt><dd>accounts.receivable@wynne-and-hall-group.co.uk</dd>
</dl>

<style>
  .contact {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 8pt;
    row-gap: 2pt;
    margin: 0;
    font-size: 9pt;
    break-inside: avoid;
  }
  .contact dt {
    color: #555;
    white-space: nowrap;
  }
  .contact dd {
    margin: 0;
    overflow-wrap: anywhere;      /* long addresses break instead of overflowing */
    hyphens: none;                /* never hyphenate an address */
  }
</style>

What breaks when it is built the obvious way

Testing with short example addresses. Every sample dataset uses names at four-letter domains, and every real one eventually contains a forty-character address at a hyphenated company domain. Put your longest realistic address in the fixture and leave it there.

How to prove it survived pagination

Render the block at the narrowest column it will ever occupy, with the longest email address and the longest URL your data can hold. Nothing should cross the column edge, and no hyphen should have been inserted into either.

Where it sits in a finished document

This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The business letter template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.

Frequently asked

Will this fragment work on its own?

Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.

Why does it look right in a browser and wrong in the PDF?

Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.

Do I need a special option on the render request for this?

No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.

Other parts of a document

The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.

Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.