Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

@position-try is a CSS at-rule that defines a named fallback layout for an anchor-positioned element. Defining an option is only half the job: you must also list its name on the element with position-try-fallbacks or the position-try shorthand.

What @position-try does

Anchor positioning lets an element be placed relative to another element, called its anchor. If the positioned element would overflow its inset-modified containing block or the viewport, the browser can try alternative placements. @position-try gives you a way to define a named custom alternative, including changes to placement, spacing, sizing, or alignment.

The at-rule has this form:

@position-try --try-option-name {
  /* supported descriptors */
}

The name is a dashed identifier, such as --custom-bottom. The rule defines the option; it does not apply it automatically. The anchor-positioned element must refer to that name.

Define an option and connect it to an element

This example defines a below-anchor alternative for a fixed infobox and asks the browser to prefer the fallback that provides the most height:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
@position-try --custom-bottom {
  top: anchor(bottom);
  bottom: unset;
  margin-top: 10px;
}

.infobox {
  position: fixed;
  position-anchor: --my-anchor;
  bottom: anchor(top);
  margin-bottom: 10px;
  justify-self: anchor-center;
  position-try: most-height --custom-bottom;
}

The custom option changes the element’s placement to below the anchor and sets a top margin. The position-try shorthand connects the option to the infobox and sets its fallback ordering preference. This is a documented usage pattern, not a guarantee that this exact layout fits every page or viewport.

What you can change in a custom option

A @position-try rule can contain descriptors for position area or inset values, margins, sizing, and self-alignment. When the browser applies the option, its declared values take precedence over corresponding standard property values on the element. This lets a fallback change more than just which side of the anchor the element occupies.

How the browser chooses a fallback

The element’s fallback names are candidates, not simultaneous styles. The browser tries the alternatives when the positioned element would overflow its relevant containing block or the viewport, and uses an option that avoids overflow when one fits.

  • Candidate choice: use named custom options such as those declared with @position-try, or built-in position-area and try-tactic options where appropriate.
  • Ordering: with the default normal order, the browser tests alternatives in the order listed. A try-size preference such as most-height can prioritize the option that yields more height.
  • Layout effect: each option can change placement and may also change spacing, sizing, or alignment. Choose alternatives that make sense for the content and available space.

For details on the shorthand and ordering behavior, see MDN’s position-try property reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser support

MDN marks @position-try Baseline 2026 and says it has been available across the latest devices and browser versions since January 2026. That broad status does not mean every older browser or device supports it. Check a current compatibility table against the browser versions your site needs to support before relying on the feature in production. MDN’s @position-try reference documents the syntax, descriptors, example, and status.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.