Sub topic 10
Writing and hiding preheader text
This chapter assumes you know basic HTML and CSS, and that you have read the earlier chapters on table layout and inline CSS. It covers the preheader, the short preview line that many inboxes show next to the subject.
What the preheader is
The preheader is the snippet of text a mail client shows after the subject line in the message list. On phones it often appears on a second line under the subject. Clients build it from the first readable text in the HTML body. If you add nothing, the client uses whatever comes first. That is often "View in browser", a logo's alt text, or a navigation link, and it wastes space that could encourage someone to open the message.
The fix is to put a deliberate sentence at the very start of the body, then hide it from the rendered message.
Writing the text
Treat the preheader as a second subject line that adds information instead of repeating it.
- Aim for roughly 40 to 90 characters. Clients truncate at different lengths, so put the important part first.
- Complete the thought of the subject. If the subject is "Your order is confirmed", the preheader can say "Arrives Friday. Track it anytime."
- Write plain text. Do not include links or images in this block.
- Write a different preheader for each message, not one reused template string.
Hiding it in the page
The preheader should be invisible to readers of the opened email but still present in the HTML. This block goes immediately after the opening <body> tag:
<div style='display:none;max-height:0;overflow:hidden;opacity:0;mso-hide:all;font-size:1px;line-height:1px;color:#f4f4f4;'>
Your order has shipped and should arrive on Friday. ‌ ‌ ‌
</div>Each declaration covers a different client behavior:
| Declaration | Purpose |
|---|---|
| `display:none` | Removes the block from layout in most clients |
| `max-height:0; overflow:hidden` | Collapses the block in clients that ignore `display:none` |
| `opacity:0` | Makes any remaining text invisible |
| `mso-hide:all` | Hides it in desktop Outlook, which uses the Word rendering engine |
| `font-size:1px; line-height:1px` | Shrinks any space the block might still occupy |
| `color` matching the background | Keeps the text unreadable if it does show |
Padding the preview
If your preheader is short, the client fills the rest of the preview line with the next text it finds, such as "View in browser" or your header links. To prevent this, add padding characters after the sentence. The pair ‌ is a non-breaking space followed by a zero-width non-joiner. Clients treat these as content, so they consume the remaining preview space, but readers see nothing.
Repeat the pair several times. Some tutorials add 100 or more repetitions. A modest run is enough for most clients, and you should check the result in your own tests rather than assuming a fixed number works everywhere.
Common errors
- Placing the block too late. Clients read from the top of the body, so a preheader below the header table will not be used.
- Hiding it with only
display:none. Some clients and Outlook versions still reveal the text. Keep the full set of declarations. - Repeating the subject. The preview then adds no information.
- Leaking into the visible email. If a client ignores your hiding styles, matching the text color to the background limits the damage, but test in dark mode, where that background may change.
- Forgetting accessibility. Screen readers may read hidden text in some clients. Keep the sentence meaningful and short so it does not confuse listeners if it is announced.
Exercise
Exercise
Your email has a visible "View in browser" link in the first table, and the inbox preview shows "View in browser" after the subject. What two changes fix this, and why?
Show answer
First, add a hidden preheader block as the first element after the opening body tag, containing a short sentence that complements the subject. Second, end that block with repeated ‌ pairs so that, if the sentence is short, the client does not fill the remaining preview space with the "View in browser" text. The block must come before the link because clients take preview text from the top of the body.
Exercise
Why does the hidden block use mso-hide:all in addition to display:none?
Show answer
Desktop Outlook renders with the Word engine, which may not honor display:none on its own. mso-hide:all is a Word-specific property that hides the element there.