Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Print Stylesheets | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 36 of 50

·css

Print Stylesheets

8 mins

Course progress72%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • Hide navigation and interactive elements that make no sense on paper.
  • Add `page-break-after:avoid` to keep headings with their content.
  • Use `color-adjust:exact` (Safari) to keep colors when needed.

A print stylesheet tailors the page for physical paper, removing unnecessary UI, adjusting colors, and re‑flowing content to avoid page‑break issues.

Syntax

@media print {
  /* rules that only apply when printing */
}

Typical Print Adjustments

@media print {
  /* Use a readable type size */
  html { font-size:12pt; line-height:1.4; }

  /* Hide navigation, footers, and anything that isn’t part of the core content */
  nav, .no-print, footer { display:none; }

  /* Ensure URLs are visible */
  a::after { content:" (" attr(href) ")"; }

  /* Avoid orphan headings */
  h1, h2 { page-break-after:avoid; }

  /* Preserve colours if the printer supports it */
  * { color-adjust:exact; }
}

Example – Printable Article

<article class="post">
  <h1>Great Article</h1>
  <p>Intro …</p>
  <section>…</section>
</article>
@media print {
  .post { max-width:65ch; margin:auto; }
  img { max-width:100%; height:auto; }
}

Pro Tip – Add a Print‑Specific Font

Serif fonts (Georgia, Times New Roman) improve readability on paper. Use a media query to switch:

@media print { body { font-family:Georgia,serif; } }

Accessibility – Do Not Hide Links Completely

The a::after rule adds the URL after the link text, guaranteeing that printed documents still convey where a link leads.

Testing

Print preview in Chrome/Firefox, then Export to PDF to verify layout. Adjust page-break-inside:avoid on large elements like tables or images to prevent awkward splits.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Accessibility – Focus Styles & Reduced MotionContinue to lesson 37CSS for EmailBack to CSS Basics to Advanced curriculum