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

tailwindcss-anchors

v0.0.2

Published

Anchors for Tailwind CSS provides a simple API for working with CSS anchor positioning, enabling flexible, declarative positioning relative to custom anchors.

Readme

minified size license version twitter

Anchors for Tailwind CSS is a plugin that brings declarative support for the CSS Anchor Positioning API to Tailwind, allowing you to define and position elements relative to custom anchors. It adds utilities for anchor-name, position-anchor, position-area, anchor() and anchor-size() expressions.

It also lays the groundwork for using View Transitions to animate any anchored elements, which would require separate JS (for now 👀).

Installation

  1. Install the plugin from npm with your preferred package manager:

    npm install -D tailwindcss-anchors
  2. Then include it in your Tailwind CSS or JS config file:

    /* style.css */
    @import "@toolwind/anchors";
    // tailwind.config.js
    import anchors from "@toolwind/anchors";

Usage

Defining an anchor

Use the anchor/{name} utility to define an anchor point:

<div class="anchor/my-anchor"></div>

The CSS anchor-name property requires a dashed ident. For convenience, Anchors for Tailwind CSS automatically converts simple names into dashed idents.

For example, the above utility generates this CSS, prefixed with --tw-anchor_:

.anchor\/my-anchor {
  anchor-name: --tw-anchor_my-anchor;
}

If you need to use a specific dashed ident for an anchor name, the plugin will respect and preserve the original name if it encounters an ident that is already dashed.

<div class="anchor/--my-anchor"></div>

This utility also accepts arbitrary values, so if you want to pass a name via a CSS variable, you can do so using the square bracket syntax, like this:

<div class="[--custom-property:--my-anchor]">
  <div class="anchor/[var(--custom-property)]"></div>
</div>

🚧 Note that names passed via a custom property (square bracket syntax) resolves to a dashed ident already, as it's not possible for a plugin to read and manipulate runtime values.

Positioning relative to an anchor

Once an anchor has been defined, you can anchor other elements to it.

Use anchored/{name} to attach an element to an anchor:

<div class="anchored/my-anchor"></div>

Use anchored-{side} to specify the position area of the anchored element. For example, anchored-top-center will position the element at the top center of its anchor, touching the anchored element:

<div class="anchored-top-center"></div>

Or, put both together for shorthand syntax:

<div class="anchored-top-center/my-anchor"></div>

This sets:

position-anchor: --tw-anchor_my-anchor;
position-area: top center;
position: absolute;
view-transition-name: --tw-anchor-view-transition-313d192p322r2w3336;
/* ☝️ View Transition-ready, with encoded view-transition-name */

Both the position and view-transition-name are applied with zero specificity (via :where()), making them easy to overwrite with other values, if you choose. As a rule of thumb, anchored elements must use absolute or fixed positioning. This plugin defaults to absolute positioning, but you can add fixed to use fixed positioning instead.

This plugin strives to strike a balance between abstracting away the complexity of the CSS Anchor Positioning API and empowering developers to fully leverage it.

Supported Utilities

anchor/{name}

Sets anchor-name: --tw-anchor_{name}

anchored/{name}

Sets:

  • position-anchor: --tw-anchor_{name}
  • view-transition-name (automatically generated per anchor)

anchor-{position}

Sets position-area. Examples:

  • anchor-top-centertop center
  • anchor-bottom-span-left
  • anchor-top-right, etc.

{top|right|bottom|left|inset}-anchor-{side}-{offset}/{name?}

Generates directional offset using anchor():

<div class="top-anchor-bottom"></div>

Results in:

top: anchor(bottom);

With offset support:

<div class="top-anchor-bottom-4"></div>
top: calc(anchor(bottom) + 1rem); // assuming 4 = theme('spacing.4')

{w|h}-anchor{-size?}/{name?}]

Size utilities using anchor-size():

  • Omitting the anchor size (i.e. default size/dimension)

    w-anchorwidth: anchor-size(width) If the {size} is omitted, the dimension defaults to the <anchor-size> keyterm that matches the axis of the property in which the function is included. For example, width: anchor-size(); is equivalent to width: anchor-size(width);. (source: MDN)

  • Declaring the anchor-size (width/height/etc.) to use as a length

    w-anchor-heightwidth: anchor-size(height)

  • Setting/omitting the anchor name

    • w-anchorwidth: anchor-size(width)
    • w-anchor/--namewidth: anchor-size(--name width)
    • w-anchor/namewidth: anchor-size(--tw-anchor_name width)

    Specifying an <anchor-name> inside an anchor-size() function neither associates nor tethers an element to an anchor; it only defines which anchor the element's property values should be set relative to. (source: MDN)

View Transition API Integration

Every anchored/{name} class includes a view-transition-name, making your anchored elements animatable with document.startViewTransition():

document.startViewTransition(() => {
  el.classList.remove('anchor-top-left')
  el.classList.add('anchor-bottom-right')
})

This animates position shifts smoothly using the browser-native View Transitions API.

Why use Anchors for Tailwind CSS? 🤔

  • Declarative anchor positioning with Tailwind utility syntax
  • Full support for native anchor-related CSS properties and functions
  • Easy offset control via calc(anchor(...) + theme spacing) (under the hood)
  • Built-in support for View Transitions
  • Fully JIT-compatible, no runtime required

Additional Resources 📚

Coming soon 👀🤞

Some relevant features that are not part of this plugin yet are:

  • anchor-center
  • position-try-order | position-try-fallbacks | position-try
  • position-visibility

If you liked this plugin...

Check out more by @branmcconnell: