npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

light-print

v2.7.0

Published

Lightweight HTML element printing for browsers.

Downloads

27

Readme

light-print

ci Codecov npm bundle size npm license

🖨️ Lightweight HTML element printing for browsers.

🚀 View an online usage example.

  • Lightweight: Zero Dependencies & 3KB minzipped
  • Auto-Styled: Preserves the existing styles without extra CSS setup
  • Callback-Free: Native promise handling for print workflows

Install

npm i light-print
# or
yarn add light-print
# or
pnpm add light-print

CDN

<!-- After importing, `window.lightPrint` is globally available. -->
<script src="https://cdn.jsdelivr.net/npm/light-print@2"></script>

If the browser doesn't support Promise (e.g., Internet Explorer), a global polyfill is required.

Usage

Print container elements and their descendants.

After the browser displays the print dialog:

  • Select any printer to print
  • Select the "Save as PDF" option to generate a PDF file.
import lightPrint from 'light-print';

lightPrint('#id', {
  // Modify different aspects of printed pages.
  mediaPrintStyle: '@page { size: A4 portrait }',
}).then(() => {
  // Executes when the print dialog closes.
});
  • Accepts either a CSS selector or an actual element.
  • Returns a Promise that resolves when the print dialog closes.

Usage in Vue

<script setup>
import { useTemplateRef } from 'vue';
import lightPrint from 'light-print';
// Prior to Vue v3.5, we could declare a `ref` matching the name of the template’s ref attribute value.
const targetRef = useTemplateRef('target');

async function print() {
  await lightPrint(targetRef.value);
}
</script>

<template>
  <div ref="target">
    <!-- some nodes -->
  </div>
</template>

Usage in React

import { useRef } from 'react';
import lightPrint from 'light-print';

function MyComponent() {
  const targetRef = useRef(null);

  async function print() {
    await lightPrint(targetRef.current);
  }

  return <div ref={targetRef}>{/* some nodes */}</div>;
}

The same approach works with other frameworks/libraries.

Types

interface PrintOptions {
  /** Document title */
  documentTitle?: string;
  /** Additional print styles */
  mediaPrintStyle?: string;
  /** Document zoom level */
  zoom?: number | string;
}

function lightPrint(containerOrSelector: Element | string, options?: PrintOptions): Promise<void>;

FAQ

  1. Is this compatible with React/Vue/Angular?

    Works with all frameworks! See our framework examples.

  2. How to handle page breaks?

    Use CSS page break properties, e.g.

    .page-break {
      page-break-after: always;
      break-after: page;
    }
  3. How to implement headers/footers?

    Configure via paged media in the mediaPrintStyle, or set page margins to zero and manually implement the DOM structure for headers/footers.

  4. Why are some styles missing after printing?

    Because those styles may be inherited from the parent; you need to restate them (e.g., background) directly on the print-element container.

Limitations

  • It is recommended to specify fixed dimensions (width and height) for the print-element container, as it cannot adapt to page dimensions when printing.
  • Automatic font loading is not supported for non-Chromium browsers. You can declare @font-face within the mediaPrintStyle, for example:
    const mediaPrintStyle = `
      @font-face {
        font-family: 'PrintFont';
        src: url('print-font.woff2') format('woff2');
      }
    `;