Print stylesheet for a resume page
A small React resume component with print CSS that sets A4 page margins, hides controls and avoids awkward page breaks.
React / Next.jsLayoutsprintcssresumereact
Live preview
Code
'use client';
import './resume-print.css';
type Job = { company: string; title: string; period: string; points: string[] };
type Props = { name: string; role: string; summary?: string; jobs: Job[] };
export function Resume({ name, role, summary, jobs }: Props) {
return (
<>
<div className="no-print toolbar">
<button type="button" onClick={() => window.print()}>
Print or save as PDF
</button>
</div>
<article className="resume">
<header>
<h1>{name}</h1>
<p className="role">{role}</p>
</header>
{summary && <p>{summary}</p>}
<h2>Experience</h2>
{jobs.map((job) => (
<section key={job.company + job.period} className="job">
<h3>
{job.title}, {job.company} <span>{job.period}</span>
</h3>
<ul>
{job.points.map((p) => (
<li key={p}>{p}</li>
))}
</ul>
</section>
))}
</article>
</>
);
}
.resume { max-width: 210mm; margin: 1rem auto; padding: 16mm; background: #fff; color: #111; font: 14px/1.5 system-ui, sans-serif; box-shadow: 0 1px 8px rgb(0 0 0 / 0.15); }
.resume header { border-bottom: 2px solid #2563eb; margin-bottom: 1rem; }
.resume h1 { margin: 0; font-size: 28px; }
.resume .role { margin: 0 0 0.5rem; color: #2563eb; }
.resume h2 { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.resume h3 { margin: 0; font-size: 15px; }
.resume h3 span { float: right; font-weight: 400; color: #555; }
.toolbar { text-align: center; padding: 0.5rem; }
@page { size: A4; margin: 16mm; }
@media print {
body { background: #fff; }
.no-print { display: none !important; }
.resume { margin: 0; padding: 0; max-width: none; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.resume h2, .resume h3 { break-after: avoid; }
.resume .job { break-inside: avoid; }
.resume a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 11px; color: #555; }
}
How it works
What it solves
Letting visitors print or save their resume as a PDF is a cheap alternative to server-side PDF generation, but the browser default output is poor: toolbars appear, backgrounds vanish, headings strand at the bottom of a page and margins are inconsistent. A focused print stylesheet fixes all of that.
How it works
The component renders an article with sections and a screen-only toolbar holding a print button that calls window.print(). The stylesheet has two layers. On screen, the article is a centred white sheet with a width approximating A4, so the editing view resembles the output.
Inside @media print, @page sets A4 size and 16 mm margins, so margins are controlled by CSS instead of the browser dialog. Everything marked .no-print is hidden and the page background is made plain white. print-color-adjust: exact keeps accent colours and the thin header rule, which browsers otherwise strip to save ink.
Break rules prevent ugly splits: break-inside: avoid on each job entry keeps it in one piece, and break-after: avoid on headings stops a heading sitting alone at the end of a page. Links print with their address using an a::after rule, which is useful on paper.
Adapting it
- Use
@page :firstfor a different first-page margin. - Set the paper size to
letterfor US users. - Add a page counter with the CSS
counter(page)where supported.
Pitfalls
- Browsers ignore custom page sizes inconsistently; test Chrome and Safari.
- Remember users must enable background graphics in some dialogs unless
print-color-adjustis honoured.
How to use it
- Save
Resume.tsxandresume-print.cssincomponents/. - Import the stylesheet from the component (already done); Next.js bundles it.
- Pass your data:
<Resume name="Ada Example" role="Engineer" jobs={[...]} />. - Click the print button and choose "Save as PDF" in the dialog.
Licence: DEV3 Snippet Licence. Free to use, change and ship in personal and commercial projects. Attribution is appreciated, not required. Please do not redistribute snippets as a collection.