Lab 09: Print & Email CSS

Time: 30 minutes | Level: Advanced | Docker: docker run -it --rm node:20-alpine sh

Overview

Master print CSS (@media print, @page, orphans/widows), HTML email fundamentals (table-based layouts, inline styles, client quirks), and the MJML framework.


Step 1: Print Media Query

/* Separate print stylesheet */
<link rel="stylesheet" href="print.css" media="print">

/* Or inline in main stylesheet */
@media print {
  /* ALL print styles here */
}

/* Avoid: avoid loading print stylesheet for screen */
/* Use: @media print {} for co-location */
/* Essential print resets */
@media print {
  /* Remove backgrounds (save ink) */
  *, *::before, *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  /* Remove interactive elements */
  nav, aside, .sidebar, .no-print,
  header .nav, footer .social-links,
  .cookie-banner, .chat-widget,
  video, audio, iframe {
    display: none !important;
  }
  
  /* Ensure links are readable */
  a, a:visited { text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; }
  abbr[title]::after { content: " (" attr(title) ")"; }
  
  /* Don't show hash/javascript links */
  a[href^="#"]::after,
  a[href^="javascript:"]::after { content: ""; }
  
  /* Show images */
  img { max-width: 100% !important; }
  
  /* Page break rules */
  thead { display: table-header-group; } /* repeat table header on each page */
  tr, img { page-break-inside: avoid; }
  
  /* Typography */
  body {
    font-size: 12pt;
    line-height: 1.5;
    font-family: Georgia, serif;
  }
}

Step 2: @page Rule


Step 3: Page Breaks, Orphans, Widows


Step 4: HTML Email Fundamentals

Email clients ignore most modern CSS. The rules:


Step 5: Email Client Quirks


Step 6: Responsive Email


Step 7: MJML Framework


Step 8: Capstone — Print CSS Generator

(Create the file:)

📸 Verified Output:


Summary

Feature
CSS
Support

Print media

@media print {}

Universal

Page size

@page { size: A4 }

Modern browsers

Page margins

@page { margin: 2cm }

Universal

Page break

break-before: page

Modern (+ legacy)

Orphans/widows

orphans: 3

Most browsers

Email layout

Table-based HTML

All clients

Inline styles

Required for email

All clients

Responsive email

@media in <style>

Most clients

MJML

Component-based

Compiles to HTML

Outlook VML

<!--[if mso]>

Outlook only

Last updated