Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท At-rules

The @position-try at-rule

Reference for the CSS @position-try at-rule: define named fallback positions that an anchored element tries when its first choice would overflow the viewport.

The @position-try at-rule defines a named position option for an element that is placed with anchor positioning. You give it a dashed name, such as --below, and a short list of positioning declarations. The element lists those names in position-try-fallbacks, and the browser tries them in order when the default position would overflow its containing block, which is usually the viewport.

Typical use: a tooltip that sits above its button, but flips below when the button is at the top of the screen.

CSS
@position-try --below {
  position-area: bottom;
  margin: 8px 0 0;
}

Try it

This feature is new, so the example needs a browser with anchor positioning. If you see the tooltip text in the normal flow below the button, your browser does not support it yet.

Flip a tooltip when there is no room

The button sits at the top of the page, so there is no room above it. The browser skips the first choice and uses --below, putting the tooltip underneath.

Syntax

CSS
@position-try <dashed-ident> {
  <declaration-list>
}

It is an at-rule, so initial value, inheritance and animatability do not apply.

Syntax and arguments

Part Description
<dashed-ident> The option's name. It must start with two hyphens and is referenced from position-try-fallbacks.
Inset properties top, right, bottom, left, their logical forms and inset.
Margin properties All margin-* properties.
Sizing properties width, height, min-*, max-*, and the logical size properties.
Self-alignment align-self, justify-self, place-self.
position-anchor, position-area Switch to another anchor or area.

Any other property inside the block is ignored.

Usage notes

  • The fallback replaces, it does not merge. The listed declarations override the element's own values for the same properties while that option is active.
  • Tried in order. The first option whose box fits within the containing block wins. If none fits, the base position is kept.
  • Inline alternative. For simple flips, position-try-fallbacks: flip-block, flip-inline needs no @position-try rule at all.
  • Dashed names only. --below works; plain below is a syntax error.
  • Mind your own margins. The margin in the fallback is how you keep a gap from the anchor. A margin from the base rule is not reused.
  • Set position: fixed or absolute. Anchor positioning only applies to absolutely positioned boxes.

Browser support

Supported in Chromium-based browsers and in Safari 26. Firefox support is still in progress at the time of writing, so check current compatibility data and keep a plain fallback layout.