CSS position-try-order Property

The CSS position-try-order property controls how a browser prioritizes possible positions for an anchor-positioned element when alternative placements are available.

It is part of CSS Anchor Positioning and works with position-try-fallbacks to help tooltips, menus, popovers, and other floating elements fit within the available display area. The property can preserve the normal fallback order or prioritize positions with more available width or height.

position-try-order Syntax

The position-try-order property accepts a single keyword that determines how candidate positions are prioritized.

Basic Syntax

selector {
  position-try-order: normal;
}

Available Values

.tooltip {
  position-try-order: normal;
}
.tooltip {
  position-try-order: most-width;
}
.tooltip {
  position-try-order: most-height;
}
.tooltip {
  position-try-order: most-block-size;
}
.tooltip {
  position-try-order: most-inline-size;
}

CSS-Wide Keywords

.tooltip {
  position-try-order: initial;
}
.tooltip {
  position-try-order: inherit;
}
.tooltip {
  position-try-order: unset;
}
.tooltip {
  position-try-order: revert;
}
.tooltip {
  position-try-order: revert-layer;
}

Only one selection-order keyword can be specified at a time.

Property Values

Value Description
normal Uses the preferred position when it fits, then considers fallback options in their specified order. This is the initial value.
most-width Prioritizes candidate positions according to the greatest available physical width.
most-height Prioritizes candidate positions according to the greatest available physical height.
most-block-size Prioritizes candidate positions according to the greatest available size along the logical block axis.
most-inline-size Prioritizes candidate positions according to the greatest available size along the logical inline axis.
initial Resets the property to normal.
inherit Uses the computed value from the parent element.
unset Resets the property to normal because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited No
Applies to Absolutely positioned elements
Computed value As specified
Animation type Discrete
Percentages Not applicable

Valid Values

.tooltip {
  position-try-order: normal;
}
.menu {
  position-try-order: most-width;
}
.popover {
  position-try-order: most-height;
}
.label {
  position-try-order: most-inline-size;
}

Invalid Values

.tooltip {
  position-try-order: auto;
}
.tooltip {
  position-try-order: flip-block;
}
.tooltip {
  position-try-order: 100px;
}
.tooltip {
  position-try-order: most-width most-height;
}
.tooltip {
  position-try-order: largest;
}

The property accepts only supported selection-order keywords. Flip options belong to position-try-fallbacks, while lengths and arbitrary sizing words are not valid values.

How It Works

When an anchor-positioned element has fallback options, the browser evaluates possible placements to find one that fits within the applicable overflow constraints.

The position-try-order property influences the order in which those positions are considered.

Step 1: Establish an Anchor

.help-button {
  anchor-name: --help-anchor;
}

Step 2: Define the Preferred Placement

.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: bottom;
}

The tooltip initially prefers the area below its anchor.

Step 3: Provide Fallback Positions

.tooltip {
  position-try-fallbacks: flip-block, flip-inline;
}

The browser now has alternative placements it can try if the preferred position does not fit.

Step 4: Choose a Selection Order

.tooltip {
  position-try-order: most-height;
}

The browser prioritizes the candidate with the greatest available height before applying the fitting rules.

Step 5: Select a Position

The browser evaluates the candidate positions in the applicable order and uses a fitting option when one is available.

Important Distinction

The position-try-fallbacks property defines alternative positions. The position-try-order property controls their priority.

Normal Fallback Order

The normal value preserves the preferred placement and the order of the fallback list.

Example

.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: bottom;
  position-try-order: normal;
  position-try-fallbacks: flip-block, flip-inline;
}

With this configuration, the browser evaluates the positions in the following order:

  1. The preferred position below the anchor.
  2. The block-axis flipped position.
  3. The inline-axis flipped position.

The first position that fits is selected.

Changing the Fallback Order

.tooltip {
  position-try-order: normal;
  position-try-fallbacks: flip-inline, flip-block;
}

The inline-axis flip is now considered before the block-axis flip when the preferred position does not fit.

When to Use normal

Use normal when maintaining a specific visual placement is more important than maximizing available space.

Important Consideration

The preferred position remains the first choice under normal ordering, provided it fits within the applicable constraints.

Physical Size Priorities

The most-width and most-height values prioritize candidate positions based on available physical dimensions.

most-width

.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: right;
  position-try-fallbacks: flip-inline;
  position-try-order: most-width;
}

The browser compares the available width of the candidate positions. This is useful when a tooltip or menu contains text that benefits from additional horizontal space.

most-height

.menu {
  position: absolute;
  position-anchor: --menu-anchor;
  position-area: bottom;
  position-try-fallbacks: flip-block;
  position-try-order: most-height;
}

The browser prioritizes the position with the greatest available height. This is useful for dropdown menus, lists, and panels containing several items.

Comparing the Values

Value Priority Typical Use
most-width Available horizontal space Wide tooltips, text panels, and horizontal menus
most-height Available vertical space Dropdown menus, lists, and tall popovers

Important Consideration

These values compare available space, not the element's actual rendered width or height. A candidate with more available space is not necessarily the one closest to the preferred placement.

Logical Size Priorities

The most-block-size and most-inline-size values use logical dimensions that follow the writing mode.

most-block-size

.menu {
  position: absolute;
  position-anchor: --menu-anchor;
  position-area: block-end;
  position-try-fallbacks: flip-block;
  position-try-order: most-block-size;
}

The browser prioritizes the candidate with the greatest available block-axis size.

In a typical horizontal writing mode, the block axis is vertical. In a vertical writing mode, it is horizontal.

most-inline-size

.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: inline-end;
  position-try-fallbacks: flip-inline;
  position-try-order: most-inline-size;
}

The browser prioritizes the candidate with the greatest available inline-axis size.

Physical Versus Logical Sizing

Physical Value Logical Value Difference
most-width most-inline-size Physical width is always horizontal, while inline size follows the writing mode.
most-height most-block-size Physical height is always vertical, while block size follows the writing mode.

When to Use Logical Values

Logical values are useful for multilingual interfaces and layouts that support horizontal and vertical writing modes.

Important Consideration

Logical dimensions follow the applicable writing mode. Choose them when the layout should adapt to text orientation rather than remain tied to physical width or height.

Working With Fallback Positions

The position-try-order property does not create fallback positions. It controls how existing candidates are prioritized.

Define the Fallback List

.tooltip {
  position-try-fallbacks: flip-block, flip-inline;
}

Set the Selection Order

.tooltip {
  position-try-order: most-height;
}

Combined Example

.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: bottom;
  position-try-fallbacks: flip-block, flip-inline;
  position-try-order: most-height;
}

The browser has three candidate placements: the original position and two generated fallbacks. It uses the available-height priority when evaluating these positions.

Using the position-try Shorthand

.tooltip {
  position-try: most-height flip-block, flip-inline;
}

This is equivalent to:

.tooltip {
  position-try-order: most-height;
  position-try-fallbacks: flip-block, flip-inline;
}

Using Custom Fallbacks

@position-try --above-anchor {
  position-area: top;
}
@position-try --left-of-anchor {
  position-area: left;
}
.tooltip {
  position: absolute;
  position-anchor: --help-anchor;
  position-area: bottom;
  position-try-fallbacks: --above-anchor, --left-of-anchor;
  position-try-order: most-width;
}

The browser can compare the preferred position and the two custom alternatives according to their available width.

Important Consideration

When position-try-fallbacks is none, changing position-try-order does not provide any additional positions to try.

position-try-order Example

The following example uses most-height to prioritize the position with the greatest available vertical space. The anchored panel can appear above or below its button, depending on the available space.

HTML Example

<div class="position-order-demo">
  <button class="demo-button" type="button">Menu Button</button>
  <div class="demo-panel">
    <strong>Example Menu</strong>
    <p>This panel uses available-height positioning.</p>
  </div>
</div>

CSS Example

.position-order-demo {
  position: relative;
  min-height: 220px;
  padding: 80px 20px 20px;
  text-align: center;
  border: 2px solid #94a3b8;
  background-color: #f1f5f9;
}
.position-order-demo .demo-button {
  anchor-name: --menu-anchor;
  padding: 10px 18px;
  border: 0;
  border-radius: 4px;
  background-color: #2563eb;
  color: #ffffff;
}
.position-order-demo .demo-panel {
  position: absolute;
  position-anchor: --menu-anchor;
  position-area: bottom;
  position-try-fallbacks: flip-block;
  position-try-order: most-height;
  width: 220px;
  max-width: calc(100vw - 40px);
  margin: 8px;
  padding: 12px;
  border-radius: 4px;
  background-color: #1e293b;
  color: #ffffff;
  text-align: left;
}
@supports not ((position-anchor: --menu-anchor) and (position-area: bottom) and (position-try-order: most-height)) {
  .position-order-demo .demo-panel {
    top: 135px;
    left: 50%;
    transform: translateX(-50%);
  }
}
Browser Result
Example Menu

This panel uses available-height positioning.

The panel prefers the area below the button, but the browser can prioritize the block-axis flipped position when it offers more available height.

The selected position depends on the viewport, the anchor's location, and the available space. The fallback may not activate in every layout.

Changing to Normal Order

.position-order-demo .demo-panel {
  position-try-order: normal;
}

With normal, the browser prefers the original bottom placement when it fits, regardless of whether the top placement offers more space.

Prioritizing Width Instead

.position-order-demo .demo-panel {
  position-try-order: most-width;
}

This changes the priority from available height to available width.

Accessibility Considerations

The position-try-order property changes visual placement without changing an element's document order or accessibility semantics.

Maintain Logical Source Order

Keep anchored content near its related control in the HTML structure whenever practical.

Preserve Keyboard Navigation

Menus, popovers, and other interactive elements must remain accessible through keyboard navigation regardless of their selected position.

Avoid Obscuring Controls

Test alternative placements to ensure anchored elements do not cover important controls or focused content.

Support Zoom and Text Resizing

Increased zoom and larger text can change the available space and cause a different position to be selected.

Maintain Visible Focus

Ensure focus indicators remain visible when a positioned element changes placement.

Use Appropriate Semantics

Positioning properties do not provide menu, tooltip, or popover interaction behavior. Use appropriate HTML elements and accessibility relationships.

Common Mistakes

Using position-try-order Without Fallbacks

.tooltip {
  position-try-order: most-height;
}

Without fallback options, the property has no alternative placements to prioritize.

Using Flip Keywords as Values

.tooltip {
  position-try-order: flip-block;
}

The flip-block keyword belongs to position-try-fallbacks, not position-try-order.

Specifying Multiple Order Keywords

.tooltip {
  position-try-order: most-width most-height;
}

Only one selection-order keyword is allowed.

Confusing Available Space With Element Size

The most-width and most-height values compare available positioning space. They do not directly set the element's dimensions.

Confusing Physical and Logical Dimensions

most-width always refers to physical width. most-inline-size follows the logical inline axis, which can be vertical in some writing modes.

Expecting the Preferred Position to Always Win

With size-based ordering, a fallback position can take priority over the original position when it offers more available space.

Expecting Guaranteed Overflow Prevention

The browser can select only from the available candidates. If none fits, overflow may still occur.

Assuming Universal Browser Support

CSS Anchor Positioning is a newer feature. Provide appropriate fallback styles for browsers without support.

Important Considerations

Keep the following points in mind when using position-try-order:

  • It controls how candidate positions are prioritized.
  • It is part of CSS Anchor Positioning.
  • Its initial value is normal.
  • The property is not inherited.
  • It applies to absolutely positioned elements.
  • It does not create fallback positions.
  • Use position-try-fallbacks to define alternative placements.
  • Use position-area or anchor-based inset properties to define preferred placement.
  • Under normal, the preferred position is used when it fits.
  • Fallbacks are considered in their specified order under normal selection.
  • most-width prioritizes available physical width.
  • most-height prioritizes available physical height.
  • most-block-size prioritizes available logical block size.
  • most-inline-size prioritizes available logical inline size.
  • Only one selection-order keyword can be specified.
  • Physical dimensions do not change with writing mode.
  • Logical dimensions follow the applicable writing mode.
  • Size-based ordering can prioritize a fallback over the preferred position.
  • Candidate positions are still subject to fitting and overflow rules.
  • Fallback positioning does not guarantee that every element will fit.
  • The position-try shorthand combines selection order and fallback options.
  • Custom fallback positions can be defined using @position-try.
  • Browser support varies across CSS Anchor Positioning features.
  • Provide conventional positioning fallbacks when needed.
  • Test layouts near viewport and containing block boundaries.
  • Test with different content lengths, writing modes, and zoom levels.
  • Maintain accessible keyboard interactions and logical HTML order.

Browser Support

The CSS position-try-order property has Limited availability and is not supported consistently across all widely used browsers.

It belongs to the CSS Anchor Positioning feature set. Support for related properties such as position-anchor, position-area, position-try-fallbacks, and the @position-try at-rule may vary by browser and version.

For current compatibility information, visit Can I Use? and search for position-try-order.

Use feature queries and conventional positioning fallbacks when supporting browsers without the required anchor-positioning features.

Specifications

The position-try-order property is defined in CSS Anchor Positioning Module Level 1.

CSS Anchor Positioning Module Level 1

The specification defines the available selection-order keywords and how candidate positions are prioritized during anchor-positioning fallback selection.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: position-try-order