Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@oddbird/css-anchor-positioning
Advanced tools
To use the polyfill, add this script tag to your document <head>
:
<script type="module">
if (!("anchorName" in document.documentElement.style)) {
import("https://unpkg.com/@oddbird/css-anchor-positioning");
}
</script>
If you want to manually apply the polyfill, you can instead import the
polyfill
function directly from the
@oddbird/css-anchor-positioning/dist/css-anchor-positioning-fn.js
file.
For build tools such as Vite, Webpack, and Parcel, that will look like this:
import polyfill from '@oddbird/css-anchor-positioning/fn';
The polyfill
function returns a promise that resolves when the polyfill has
been applied.
You can view a more complete demo here.
The polyfill accepts one argument (type: boolean
, default: false
), which
determines whether anchor calculations should update on every animation
frame (e.g. when the
anchor element is animated using transform
s), in addition to always updating
on scroll/resize. While this option is optimized for performance, it should be
used sparingly.
<script type="module">
if (!("anchorName" in document.documentElement.style)) {
const { default: polyfill } = await import("https://unpkg.com/@oddbird/css-anchor-positioning/dist/css-anchor-positioning-fn.js");
polyfill(true);
}
</script>
When using the default version of the polyfill that executes automatically, this
option can be set by setting the value of
window.UPDATE_ANCHOR_ON_ANIMATION_FRAME
.
<script type="module">
if (!("anchorName" in document.documentElement.style)) {
window.UPDATE_ANCHOR_ON_ANIMATION_FRAME = true;
import("https://unpkg.com/@oddbird/css-anchor-positioning");
}
</script>
This polyfill was implemented against an early version of the spec, and updates were paused to allow the syntax to solidify. Now that browsers are working on implementation, we would like to bring it up to date.
While this polyfill supports many basic use cases, it doesn't (yet) support the following features:
@position-try
ruleposition-try-options
, position-try-order
, or position-try
propertiesanchor-scope
property on pseudo-elementsinset-area
propertyanchor-center
value for justify-self
, align-self
, justify-items
, and
align-items
propertiesimplicit
anchor-elementinside
or outside
anchor-sideposition-visibility
propertyinset-*
properties or inset
shorthand
propertyIn addition, JS APIs like CSSPositionTryRule
or CSS.supports
will not be
polyfilled.
At OddBird, we love contributing to the languages & tools developers rely on. We're currently working on polyfills for new Popover & Anchor Positioning functionality, as well as CSS specifications for functions, mixins, and responsive typography. Help us keep this work sustainable and centered on your needs as a developer! We display sponsor logos and avatars on our website.
FAQs
Polyfill for the proposed CSS anchor positioning spec
The npm package @oddbird/css-anchor-positioning receives a total of 1,819 weekly downloads. As such, @oddbird/css-anchor-positioning popularity was classified as popular.
We found that @oddbird/css-anchor-positioning demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.