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

tailwind-aspect-ratio

v1.0.2

Published

Tailwind plugin for aspect ratio containers

Readme

tailwind-aspect-ratio

Aspect Ratio plugin for tailwind. Generate a series of intrinsic aspect ratio containers.

Usage:

Add the plugin:

plugins: [
	// ...
    require('tailwind-aspect-ratio')
    // ...
]

Add your variants to modules as normal:

modules { 
	// ...
	aspectRatio: ['responsive'],
	// ...
}

And add config to tailwind.js like so...(omit these and all you will get is ar-base)

module.exports = {

	// ...

	
	aspectRatio: {
		'3x2': 3/2,
		'4x3': 4/3,
		'2x3': 2/3,
		'5x6': 5/6,
		'16x9': 16/9
	},

	// ...

}

Then if you like, change things with the tailwind options:

options: {
    prefix: '',
    important: false,
    separator: ':',
    
    // These are optional:
    aspectRatio: {
      // change the utility name. So instead of `.ar-2x3` you could have `.aspectRatio-2x3`
      prefix: '.ar-',

      // by default, it will add height 0, width 100%, position: relative and overlow:hidden.
      // but set paddingOnly and it will _only_ show the padding-bottom values. 
      // .ar-base will _still be created so you can do, for example, `ar-2x3 ar-base` for a complete application,
      // thus reducing a bit of repetition. Up to you!
      paddingOnly: false
    }
  },

Note that the aspect ratio settings just expect a number between 0 and 1. I've inverted this from the actual ratio so for a 16:9 ratio instead of supplying 0.5625 to become 56.25% you actually supply 1.7777777778

Why? Because we say 16-9 rather than 9-16, and thus in the config you can just write 16/9 - that's a bit of an opinionated thing that could get confusing so I could change it if people want to 'see' the percentages more explicitly.

Output

The examples above will output the following classes (and any variants in the config):

.ar-3x2 {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-bottom: 66.66666666666667%;
}

.ar-4x3 {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-bottom: 75%;
}

.ar-2x3 {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-bottom: 150%;
}

.ar-5x6 {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-bottom: 120%;
}

.ar-16x9 {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-bottom: 56.25%;
}

.ar-base {
  height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.ar-base

One settings-less style is generated. .ar-base will be added, so that you can supply inlined padding-bottom, such as server-side generated image dimensions.

<div class="ar-base" style="padding-bottom: 56.25%"> ... </div>

Suggestions / Todo

  • Maybe we could add some config for the base style, i.e. adding position:relative is done because you're almost certainly going to put an absolute container in there. You're most likely to going to want to fill a container by 100% rather than have the aspect-ratio container be a percentage width itself (because then padding-bottom becomes tiresome). But hey, a project might want some differences to the 'base' and we could pass in a config for that....