Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@oddbird/css-anchor-positioning
Advanced tools
Polyfill for the proposed CSS anchor positioning spec
The CSS anchor positioning specification defines anchor positioning, "where a positioned element can size and position itself relative to one or more 'anchor elements' elsewhere on the page." This CSS Anchor Positioning Polyfill supports and is based on this specification.
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 supports a small number of options. When using the default version
of the polyfill that executes automatically, options can be set by setting the
value of window.ANCHOR_POSITIONING_POLYFILL_OPTIONS
.
<script type="module">
if (!("anchorName" in document.documentElement.style)) {
window.ANCHOR_POSITIONING_POLYFILL_OPTIONS = {
elements: undefined,
excludeInlineStyles: false,
useAnimationFrame: false,
};
import("https://unpkg.com/@oddbird/css-anchor-positioning");
}
</script>
When manually applying the polyfill, options can be set by passing an object as an argument.
<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({
elements: undefined,
excludeInlineStyles: false,
useAnimationFrame: false,
});
}
</script>
type: HTMLElements[]
, default: undefined
If set, the polyfill will only be applied to the specified elements instead of
to all styles. Any specified <link>
and <style>
elements will be polyfilled.
By default, all inline styles in the document will also be polyfilled, but if
excludeInlineStyles
is true, only inline styles on specified elements will be
polyfilled.
type: boolean
, default: false
When not defined or set to false
, the polyfill will be applied to all elements
that have eligible inline styles, regardless of whether the elements
option is
defined. When set to true
, elements with eligible inline styles listed in the
elements
option will still be polyfilled, but no other elements in the
document will be implicitly polyfilled.
type: boolean
, default: false
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.
For legacy support, this option can also be set by setting the value of
window.UPDATE_ANCHOR_ON_ANIMATION_FRAME
, or, when applying the polyfill
manually, by passing a single boolean with polyfill(true)
.
While this polyfill supports many basic use cases, it doesn't (yet) support the following features:
position-try-order
. If try-size
is specified in position-try
shorthand, it will be parsed, and try-tactics
will be applied, but the
try-size
will be ignored.flip-start
try-tactic
is only partially supported. The tactic is
only applied to property names and anchor sides.position-area
as a try-tactic
position-anchor
.anchor-scope
property on pseudo-elementsposition-area
propertyanchor-center
value for justify-self
, align-self
, justify-items
, and
align-items
propertiesinside
or outside
anchor-sideposition-visibility
propertyinset-*
properties or inset
shorthand
propertyposition-anchor: auto
keyword (pending resolution of
https://github.com/whatwg/html/pull/9144)In 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 3,453 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
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.