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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tailwindcss-fluid-fonts

v0.1.0

Published

The TailwindCSS Fluid Fonts plugin offers a solution for managing fluid font sizes in your project. With an easy-to-use setup this plugin perfectly suits your responsive design needs.

Downloads

7

Readme

The TailwindCSS Fluid Fonts plugin offers a solution for managing fluid font sizes in your project. With an easy-to-use setup, this plugin perfectly suits your responsive design needs.

Install

Install tailwindcss-fluid-fonts with the npm package manager:

npm i -D tailwindcss-fluid-fonts

Import and add the plugin in your Tailwind Config:

import type { Config } from "tailwindcss";
import fluidFonts from "tailwindcss-fluid-fonts";

const config: Config = {
  plugins: [
    fluidFonts({
      viewport: {
        min: "375px",
        max: "1536px",
      },
    }),
  ],
};
export default config;

Add plugin config

Viewport (Required)

Represents a range of sizes that includes min and max size of viewport.

const config: Config = {
  plugins: [
    fluidFonts({
      viewport: {
        min: "375px",
        max: "1536px",
      },
    }),
  ],
};

Font Sizes (Required)

Add a name for the font size, and as a value, you can add an array with the following structure [minFontSize, maxFontsize, lineHeight]. The third value lineHeight is optional:

Example:

const config: Config = {
  plugins: [
    fluidFonts({
      fontSizes: {
        // Without lineHeight
        "3xl": ["24px", "33px"],
        // With lineHeight
        "4xl": ["27px", "36px", "1.6"],
      },
    }),
  ],
};

When using the classes text-3xl or text-4xl, they will apply the following CSS:

/** 3xl does not add lineHeight*/
.text-3xl {
  font-size: clamp(... /* Fluid size calc */);
}

/** 4xl adds lineHeight*/
.text-4xl {
  font-size: clamp(... /* Fluid size calc */);
  line-height: 1.6;
}

Or instead of using the array type [minFontSize, maxFontsize, lineHeight], you can use an object with the following options:

  • min: minimum font size with its respective unit px or rem.
  • max: maximum font size with its respective unit px or rem.
  • lineHeight (Optional):additional option for line height.
  • letterSpacing (Optional): additional option for letter spacing.
  • fontWeight (Optional): additional option to define font weight.

Example:

const config: Config = {
  plugins: [
    fluidFonts({
      fontSizes: {
        "3xl": {
          min: "24px",
          max: "33px",
          lineHeight: "1.6",
          letterSpacing: "1px",
          fontWeight: "medium",
        },
        "4xl": {
          min: "27px",
          max: "36px",
          lineHeight: "1.6",
        },
      },
    }),
  ],
};

When using the classes text-3xl or text-4xl, they will apply the following CSS:

/** 3xl calculates font size using min and max values and adds the defined extra properties: lineHeight, letterSpacing, and fontWeight */
.text-3xl {
  font-size: clamp(... /* Fluid size calc */);
  line-height: 1.6;
  letter-spacing: 1px;
  font-weight: medium;
}

/** 4xl calculates font size using min and max values and adds the defined extra property: lineHeight */
.text-4xl {
  font-size: clamp(... /* Fluid size calc */);
  line-height: 1.6;
}

Unit (Optional: Default: "rem")

Unit used as output for font sizes can be px or rem:

Example:

If font size values (min and max) are defined in px and unit is defined in rem, the value of the font-size property in the CSS will be defined using rem;

const config: Config = {
  plugins: [
    fluidFonts({
      fontSizes: {
        "4xl": ["27px", "36px"],
      },
      viewport: {
        min: "375px",
        max: "1536px",
      },
      unit: "rem", //Default
    }),
  ],
};

Output if the unit is rem:

.text-4xl {
  font-size: clamp(
    1.6875rem,
    calc(1.6875rem + (2.25 - 1.6875) * ((100vw - 23.4375rem) / (96 - 23.4375))),
    2.25rem
  );
}

Output if the unit is px:

.text-4xl {
  /** The calc base value MUST be stated in REM to maintain accessibility */
  font-size: clamp(27px, calc(1.6875rem + (36 - 27) * ((100vw - 375px) / (1536 - 375))), 36px);
}

If font size values (min and max) are defined in rem and unit is defined in px, the value of the font-size property in the CSS will be defined using px;