Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To show a hyperlink’s destination on paper or in a PDF, append its href with a print-only CSS rule. For example, this adds the URL after links that begin with https://:

@media print {
  a[href^="https://"]::after {
    content: " (" attr(href) ")";
  }
}

How the print rule works

The @media print block applies the rule to print output instead of ordinary screen presentation. MDN explains that the print media type sets styles “only [used] for printed content” (MDN: @media). Print styling can apply when printing to paper or to a PDF, although the browser’s print dialog and rendering behavior still affect the result.

The selector a[href^="https://"] matches anchor elements whose href attribute begins with https://. The ::after pseudo-element creates text after the link, and attr(href) inserts the literal value of that attribute. MDN documents this pattern for displaying fully qualified secure-link destinations (MDN: content).

Choose which links to disclose

Target only links readers need in the printed document. A broad selector such as a::after can also expose navigation links, fragment references, email addresses, or other destinations that add clutter. For an article page, scope the rule to its content container:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
@media print {
  .article-body a[href^="https://"]::after {
    content: " (" attr(href) ")";
  }
}

Adjust .article-body to match the class used by your site. The HTTPS prefix keeps fragment links such as #section, mailto: links, and non-HTTPS targets out of the output. If relative links matter, decide how they should appear: attr(href) prints the exact attribute value and does not turn a relative path into an absolute URL.

Keep the link text meaningful on its own. The generated URL is extra information for the printed copy, not a substitute for descriptive anchor text.

Choose the output format

The separator is ordinary generated text, so you can use parentheses, a label, or another delimiter. For example, to make the destination explicit:

@media print {
  .article-body a[href^="https://"]::after {
    content: " (URL: " attr(href) ")";
  }
}

Use a format that makes the boundary between the link wording and its destination easy to recognize. Long destinations may occupy extra lines, so inspect a print preview or PDF for the pages and content your readers use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Where to put the CSS

You can keep the rule in your site’s normal stylesheet inside @media print, or put it in a dedicated print stylesheet. To load a separate file only for print, add this to the page’s HTML:

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

The result remains subject to normal CSS specificity and precedence, so another print rule may override it. Test the actual browser and print-to-PDF workflow you support; identical wrapping, pagination, and generated-content behavior across browsers is not established here.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Set page layout separately

The link rule controls what text is generated after matching anchors; it does not set page dimensions or margins. Use the CSS @page rule separately for page size, orientation, margins, and related paged-media concerns. MDN’s paged-media guide covers those layout controls as well as page fragmentation (MDN: CSS paged media).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.