Preview brand Custom

Print button

A quiet button with a printer icon that opens the browser's print dialog, where a page can also be saved as a PDF. What comes out is Somnia's paper layout, not a picture of the screen.

These are live: they print this page.
Show code
astro
---
import PrintButton from '@somnia/core/components/PrintButton.astro';
---
<PrintButton />

<!-- In a panel, as a secondary button, offering both ways -->
<PrintButton variant="button" mode="all" label="Everything, opened" />
<PrintButton variant="button" mode="shown" label="Only what’s showing" />

A component of its own

It looks like a link or a button, but it isn't a variant of either. It carries the printer icon, its wording, the choice of what to print, and the rule that it is never printed itself. Pages use the component so those stay the same everywhere.

Variants

SettingValuesUse
variantlink (default), buttonA link at the end of an article or page. A secondary button inside a panel, where a link would wrap untidily under its icon.
modeall (default), shownWhat to print: see below.
label"Print or save as PDF"The words. Keep "save as PDF" in a lone button: most people don't know the print dialog does it.

Everything, or only what's showing

  • Everything (mode="all"): the whole page, with every section behind a Read more, a See more or an accordion opened. This is also what the browser's own Print does.
  • Only what's showing (mode="shown"): the page as the reader has it, closed sections left closed. For someone who opened only the parts they wanted.
  • A page that folds a lot away offers both, side by side, as Headland's yacht pages do. Other pages need only the one button.

Where it goes

  • At the end of a page someone may want to keep or pass on: a yacht, a quote, a guide, a legal page.
  • Not on every page. The browser's Print works everywhere and gives the same result.

How a page is laid out on paper is on Foundations: Print.

Do and don't

Do

  • Say "or save as PDF"
  • Offer both modes where much of the page is folded away

Don't

  • Make a "Download PDF" link to a file that has to be kept up to date by hand
  • Use an icon alone

Accessibility

What it does for you

  • A real button, 44px high, with its words visible. The icon is decoration.
  • It adds nothing a keyboard or screen reader user lacks: the browser’s own Print gives the same pages.
  • Left off the printed page and out of site search.

What you need to do

  • Keep "or save as PDF" in the words of a lone button: most people don’t know the print dialog does that.
  • Where two are offered, make the difference plain in their words: "Everything, opened" and "Only what’s showing".

Keyboard

KeyWhat it does
TabMoves to the button.
Enter or SpaceOpens the browser’s print dialog.

What a screen reader is told

  • A button named by its words: "Print or save as PDF".

This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.

WCAG 2.2

CriterionLevelHow this meets it
2.1.1 KeyboardAA native button.
2.5.3 Label in NameAIts name is its visible words.
2.5.8 Target Size (Minimum)AA44px high.
4.1.2 Name, Role, ValueAA named button.

The criteria this component has a part in. A page that uses it still has to meet the rest.

Checked

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
4 of 4 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 4 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot yet
Not yet checked by a person

The 4 checks made with the keyboard, on the example at the top of this page:

  • Passed Tab reaches the button, named by its words
  • Passed Enter opens the print dialog, asking for everything
  • Passed “Only what’s showing” tells the page to leave closed sections closed before it prints
  • Passed The button is marked to be left off the printed page

Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.

Not yet checked

  • How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
  • The printed pages themselves are checked for layout faults by the print check, not for how a screen reader reads a saved PDF.

Evidence

Where it's used

WhereFor
Headland Yachting, yacht pagesBoth buttons side by side, in the yacht’s side panel. On its staging site until launch.

What we saw, and what changed

WhenWhat we sawWhat changed
Somnia pages had just been given a paper layout of their own, which few people would find through the browser’s menu.A button that puts it one press away (1.22.1).
A yacht page folds a lot away, and printing opens all of it. Someone who had opened only what they wanted got everything."Only what’s showing" prints the page as the reader has it (1.35.0).
On an iPhone, "only what’s showing" printed 6 pages, then 16: the phone says printing is done as its sheet opens, and the page opened everything part-way through.The choice now holds until the page is next touched, which can only be after the sheet has closed (1.75.0).

From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.

What we don't know yet

  • Not counted yet: how many people print, and which button they choose. Both send an event to the site’s analytics, so this will be known once Headland is live.