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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lperezperez/fonts-css

v1.0.0

Published

Automated web font CSS generator with @font-face declarations and optional HTML specimens

Downloads

171

Readme

Banner.svg

npm version npm downloads Node.js version License: MIT Contributor Covenant 2.1.0

Automated font CSS generator
Generate CSS @font-face declarations and interactive HTML specimens from font files with intelligent auto-detection of font properties.

Table of Contents

Background

Managing web fonts often requires manually creating @font-face declarations and maintaining documentation for each font variant. This becomes tedious and error-prone when dealing with multiple font families and styles.

fonts-css automates this process by:

  • Scanning font directories (flat or organized by family)
  • Parsing font properties from filenames (weight, style, stretch)
  • Generating production-ready CSS with proper @font-face rules
  • Creating interactive HTML specimens for visual documentation
  • Supporting multiple formats (WOFF2, WOFF, TTF, OTF) in a single declaration

The tool intelligently groups font variants, calculates relative paths, and produces clean, alphabetically sorted output ready for production use.

Prerequisites

Installation

From NPM (Recommended)

# Install globally
npm install -g @lperezperez/fonts-css
# Or use with npx (no installation needed)
npx @lperezperez/fonts-css

From Source

# Clone the repository
git clone https://github.com/lperezperez/fonts-css.git
cd fonts-css
# Install dependencies
npm install
# Link globally (optional)
npm link

Dependencies

  • fs-extra - Enhanced file system operations
  • handlebars - Template engine for specimen generation

Usage

Quick Start

# Using global installation
fonts-css
# Using npx (no installation)
npx fonts-css
# With custom paths
fonts-css <input-folder> [output-folder]
# Generate only CSS (skip specimens)
fonts-css --no-specimens
fonts-css --css-only
# Show help
fonts-css --help
# Show version
fonts-css --version

CLI Options

| Option | Description | |--------|-------------| | input-dir | Directory containing font files (default: ./fonts) | | output-dir | Directory for generated files (default: same as input) | | --no-specimens | Generate only CSS, skip HTML specimens | | --css-only | Alias for --no-specimens | | -h, --help | Show help message | | -v, --version | Show version number |

Basic Examples

Example 1: Default Structure

fonts-css

Processes ./fonts and generates:

  • fonts/fonts.css - All @font-face declarations
  • fonts/specimen-{family}.html - Interactive previews per font family

Example 2: Custom Output Directory

fonts-css ./assets/fonts ./dist

Processes fonts from ./assets/fonts and outputs to ./dist with correct relative paths.

Example 3: CSS Only (Production)

fonts-css ./fonts ./dist --css-only

Generates only the CSS file without HTML specimens (ideal for production builds).

Example 4: Subdirectories by Family

fonts-css ./custom-fonts

Works with both structures:

  • Flat: fonts/FontName-Bold-Italic.woff2
  • Organized: fonts/FontName/normal-700-italic.woff2

File Naming Convention

Format: <stretch>-<weight>-<style>.<ext> | Filename | Result | |----------|--------| | normal-400-normal.woff2 | Regular | | bold-italic.woff2 | Bold Italic | | condensed-700-normal.ttf | Condensed Bold | | 300-italic.woff | Light Italic | Supported weights: 100-900 (thin, light, regular, medium, semibold, bold, extrabold, black)
Supported styles: normal, italic, oblique
Supported formats: .woff2, .woff, .ttf, .otf

Output

Generated CSS

@font-face {
	font-family: "Font Name";
	font-weight: 700;
	font-style: italic;
	src: url("./FontName/normal-700-italic.woff2") format("woff2"),
		url("./FontName/normal-700-italic.woff") format("woff");
}

HTML Specimens

Interactive previews with:

  • All font variants displayed
  • Copyable CSS rules
  • Character coverage samples
  • Modern gradient design

Integration

HTML

<!-- Link the generated CSS -->
<link rel="stylesheet" href="fonts/fonts.css">
<style>
  body {
    font-family: "Your Font", sans-serif;
    font-weight: 400;
  }
</style>

React / Next.js

// app/layout.jsx or pages/_app.jsx
import '../fonts/fonts.css';
export default function RootLayout({ children }) {
  return (
    <html>
      <body style={{ fontFamily: '"Your Font", sans-serif' }}>
        {children}
      </body>
    </html>
  );
}

Vue / Nuxt

<!-- layouts/default.vue or app.vue -->
<style>
@import '@/assets/fonts/fonts.css';

body {
  font-family: "Your Font", sans-serif;
}
</style>

Blazor

<!-- wwwroot/index.html or Pages/_Host.cshtml -->
<link rel="stylesheet" href="fonts/fonts.css">

NPM Scripts Integration

Add to your package.json:

{
  "scripts": {
    "fonts": "fonts-css ./assets/fonts ./public",
    "fonts:css": "fonts-css ./assets/fonts ./public --css-only",
    "prebuild": "npm run fonts:css"
  }
}

This automatically generates fonts CSS before each build. For more examples and detailed documentation, see:

Publishing to npm

This package uses semantic-release for automated versioning and publishing.

Commit Message Format

Follow Conventional Commits:

feat: add new feature
fix: bug fix
docs: documentation changes
chore: maintenance tasks

Release Process

  1. Merge to main branch
  2. GitHub Actions automatically:
    • Analyzes commits
    • Determines version bump
    • Updates CHANGELOG.md
    • Publishes to npm
    • Creates GitHub release

Changelog

See the Changelog for more details.

Maintainer

@Luiyi

Contribute

This repository follows the Contributors covenant code of conduct.

License

Under MIT license terms.