CSS position-try-fallbacks Property
The CSS position-try-fallbacks property defines alternative positions an anchor-positioned element can try when its preferred placement does not fit.
It is part of CSS Anchor Positioning and helps keep tooltips, dropdown menus, popovers, and other floating elements visible when space is limited. Fallback options can flip an element's placement or use custom positions defined with the @position-try at-rule.
position-try-fallbacks Syntax
The position-try-fallbacks property accepts none or a comma-separated list of fallback options. Each option can contain a named fallback, a built-in flip option, or a supported combination of flip options.
Basic Syntax
selector {
position-try-fallbacks: flip-block;
}
Available Values
.tooltip {
position-try-fallbacks: none;
}
.tooltip {
position-try-fallbacks: flip-block;
}
.tooltip {
position-try-fallbacks: flip-inline;
}
.tooltip {
position-try-fallbacks: flip-start;
}
.tooltip {
position-try-fallbacks: flip-block, flip-inline;
}
.tooltip {
position-try-fallbacks: flip-block flip-inline;
}
.tooltip {
position-try-fallbacks: --custom-position;
}
CSS-Wide Keywords
.tooltip {
position-try-fallbacks: initial;
}
.tooltip {
position-try-fallbacks: inherit;
}
.tooltip {
position-try-fallbacks: unset;
}
.tooltip {
position-try-fallbacks: revert;
}
.tooltip {
position-try-fallbacks: revert-layer;
}
Each CSS-wide keyword must be used by itself rather than combined with fallback options.
Property Values
| Value | Description |
|---|---|
none |
Specifies that no fallback positions are available. This is the initial value. |
flip-block |
Creates a fallback by flipping the preferred placement along the logical block axis. |
flip-inline |
Creates a fallback by flipping the preferred placement along the logical inline axis. |
flip-start |
Creates a fallback by exchanging the applicable start and end positioning directions. |
<dashed-ident> |
References a custom fallback position defined using the @position-try at-rule. |
initial |
Resets the property to none. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to none because the property 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 | none |
| Inherited | No |
| Applies to | Absolutely positioned elements |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
Valid Values
.tooltip {
position-try-fallbacks: flip-block;
}
.menu {
position-try-fallbacks: flip-inline, flip-block;
}
.popover {
position-try-fallbacks: flip-block flip-inline;
}
.label {
position-try-fallbacks: --alternate-position;
}
Invalid Values
.tooltip {
position-try-fallbacks: auto;
}
.tooltip {
position-try-fallbacks: 20px;
}
.tooltip {
position-try-fallbacks: top;
}
.tooltip {
position-try-fallbacks: most-width;
}
.tooltip {
position-try-fallbacks: flip-top;
}
Values such as most-width belong to position-try-order, not position-try-fallbacks. Physical placement keywords such as top belong to properties such as position-area.
How It Works
An anchor-positioned element normally uses its preferred position. When that placement does not fit within the applicable overflow constraints, the browser can evaluate alternative positions defined by position-try-fallbacks.
Step 1: Name the Anchor
.help-button {
anchor-name: --help-anchor;
}
Step 2: Define the Preferred Position
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom;
}
The tooltip's preferred placement is below the button.
Step 3: Define a Fallback
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom;
position-try-fallbacks: flip-block;
}
The browser can try a position above the anchor when the preferred placement does not fit.
Step 4: Evaluate the Positions
With the default selection order, the browser checks the preferred position first and then considers the fallback options in their specified order.
Step 5: Use a Suitable Placement
The browser selects the first position that fits under the applicable selection rules. If no candidate fits, the element may still overflow.
Important Distinction
The position-area property defines the preferred placement. The position-try-fallbacks property defines alternatives that may be used when that placement does not fit.
Built-In Flip Options
CSS provides built-in flip options that generate alternative positions without requiring a custom @position-try rule.
flip-block
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom;
position-try-fallbacks: flip-block;
}
The flip-block option reverses placement along the logical block axis. In a typical horizontal writing mode, a tooltip below its anchor can move above it.
flip-inline
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: right;
position-try-fallbacks: flip-inline;
}
The flip-inline option reverses placement along the logical inline axis. In a left-to-right horizontal writing mode, an element to the right of its anchor can move to the left.
flip-start
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom right;
position-try-fallbacks: flip-start;
}
The flip-start option exchanges applicable start and end directions. Its effect depends on the original positioning values and writing mode.
Combining Flip Options
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom right;
position-try-fallbacks: flip-block flip-inline;
}
Space-separated flip keywords create a single combined fallback option that applies both transformations.
Important Consideration
Block-axis and inline-axis flips follow writing modes. They do not always correspond to fixed physical directions.
Multiple Fallback Positions
The position-try-fallbacks property accepts multiple comma-separated options. Each option provides a separate alternative placement.
Two Separate Fallbacks
.tooltip {
position-try-fallbacks: flip-block, flip-inline;
}
With the normal selection order, the browser can try the block-axis flip first and then the inline-axis flip.
Three Fallback Options
.tooltip {
position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
}
This list provides three alternatives: a block-axis flip, an inline-axis flip, and a combined flip.
Comma Versus Space
.tooltip {
position-try-fallbacks: flip-block, flip-inline;
}
.tooltip {
position-try-fallbacks: flip-block flip-inline;
}
The first declaration provides two separate alternatives. The second declaration provides one combined alternative.
Fallback Order Matters
.tooltip {
position-try-fallbacks: flip-inline, flip-block;
}
With position-try-order: normal, the browser considers the inline-axis flip before the block-axis flip.
Important Consideration
Fallbacks do not need to cover every possible position. Choose alternatives that make sense for the interface and available space.
Custom Fallback Positions
The @position-try at-rule defines named fallback options that can specify alternative placement, sizing, and other permitted positioning declarations.
Define a Custom Fallback
@position-try --above-anchor {
position-area: top;
margin-bottom: 8px;
}
The rule defines a fallback that positions an element above its anchor.
Reference the Custom Fallback
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom;
position-try-fallbacks: --above-anchor;
}
When the preferred placement does not fit, the browser can try the position defined by --above-anchor.
Multiple Custom Fallbacks
@position-try --place-left {
position-area: left;
}
@position-try --place-right {
position-area: right;
}
.tooltip {
position: absolute;
position-anchor: --help-anchor;
position-area: bottom;
position-try-fallbacks: --place-left, --place-right;
}
The browser can try the left-side and right-side placements when the preferred bottom placement does not fit.
Mixing Built-In and Custom Fallbacks
.tooltip {
position-try-fallbacks: flip-block, --place-left, --place-right;
}
Built-in flip options and named custom fallbacks can appear in the same list.
Custom Sizing
@position-try --compact-position {
position-area: top;
max-width: 180px;
}
.tooltip {
position-try-fallbacks: --compact-position;
}
Custom fallback rules can modify supported sizing properties when an alternative placement needs different dimensions.
Important Consideration
Custom fallback identifiers begin with two hyphens. A named fallback must have a corresponding @position-try definition to provide an alternative position.
Fallback Selection
The position-try-order property controls how the browser prioritizes the preferred position and the available fallback options.
Normal Selection Order
.tooltip {
position-try-order: normal;
position-try-fallbacks: flip-block, flip-inline;
}
The browser prefers the original placement when it fits. Otherwise, it considers the fallback options in their listed order.
Prefer Available Width
.tooltip {
position-try-order: most-width;
position-try-fallbacks: flip-block, flip-inline;
}
The browser can prioritize the candidate with the greatest available width.
Prefer Available Height
.tooltip {
position-try-order: most-height;
position-try-fallbacks: flip-block, flip-inline;
}
This can be useful for menus and panels that require additional vertical space.
Using the position-try Shorthand
.tooltip {
position-try: most-height flip-block, flip-inline;
}
This shorthand sets both the fallback selection order and the fallback list.
Important Consideration
The position-try-fallbacks property defines the available alternatives. The position-try-order property determines how those alternatives are prioritized.
position-try-fallbacks Example
The following example demonstrates a tooltip that prefers a position below its anchor but can flip above it when space is limited.
HTML Example
<div class="position-fallback-demo">
<button class="demo-button" type="button">Help Button</button>
<div class="demo-tooltip">This tooltip can move above the button.</div>
</div>
CSS Example
.position-fallback-demo {
position: relative;
min-height: 180px;
padding: 25px;
text-align: center;
border: 2px solid #94a3b8;
background-color: #f1f5f9;
}
.position-fallback-demo .demo-button {
anchor-name: --demo-anchor;
padding: 10px 18px;
border: 0;
border-radius: 4px;
background-color: #2563eb;
color: #ffffff;
}
.position-fallback-demo .demo-tooltip {
position: absolute;
position-anchor: --demo-anchor;
position-area: bottom;
position-try-fallbacks: flip-block;
margin: 8px;
padding: 10px 14px;
border-radius: 4px;
background-color: #1e293b;
color: #ffffff;
}
@supports not ((position-anchor: --demo-anchor) and (position-area: bottom) and (position-try-fallbacks: flip-block)) {
.position-fallback-demo .demo-tooltip {
top: 85px;
left: 50%;
transform: translateX(-50%);
}
}
The preferred position is below the button. If that placement does not fit under the applicable overflow constraints, the browser can try the block-axis fallback.
The example may remain below the button when enough space is available. The fallback is applied only when needed.
Adding a Second Fallback
.position-fallback-demo .demo-tooltip {
position-try-fallbacks: flip-block, flip-inline;
}
This provides two alternative positions instead of one.
Using a Combined Flip
.position-fallback-demo .demo-tooltip {
position-try-fallbacks: flip-block flip-inline;
}
This defines one alternative that combines both axis flips.
Accessibility Considerations
The position-try-fallbacks property changes visual placement without changing document order or accessibility semantics.
Maintain Logical Source Order
Keep related controls and content in a meaningful HTML sequence, regardless of where fallback positioning displays them.
Preserve Keyboard Access
Interactive menus and popovers must remain accessible through keyboard navigation after their placement changes.
Avoid Obscuring Important Content
Fallback positions can reduce overflow, but anchored elements should not cover important controls or focused content.
Support Zoom and Text Resizing
Test positioned elements at increased zoom levels and with larger text, when available space may change significantly.
Maintain Focus Visibility
Ensure keyboard focus indicators remain visible when a positioned element uses an alternative placement.
Use Appropriate HTML Semantics
Tooltips, menus, and popovers should use suitable elements and accessibility relationships for their intended behavior.
Important Consideration
Fallback positioning improves visual layout but does not automatically manage focus, keyboard behavior, or screen reader relationships.
Common Mistakes
Using Fallbacks Without a Preferred Position
.tooltip {
position: absolute;
position-try-fallbacks: flip-block;
}
Define a suitable preferred position and anchor relationship so the fallback has a meaningful placement to modify.
Forgetting the Anchor Relationship
.tooltip {
position: absolute;
position-area: bottom;
position-try-fallbacks: flip-block;
}
When using named anchors, establish the relationship with anchor-name and position-anchor.
Using position-try-order Values
.tooltip {
position-try-fallbacks: most-width;
}
The most-width keyword belongs to position-try-order, not position-try-fallbacks.
Confusing Commas and Spaces
.tooltip {
position-try-fallbacks: flip-block flip-inline;
}
This creates one combined fallback. Use flip-block, flip-inline for two separate alternatives.
Using Unsupported Direction Keywords
.tooltip {
position-try-fallbacks: flip-top;
}
Use supported flip keywords such as flip-block and flip-inline.
Referencing an Undefined Custom Fallback
.tooltip {
position-try-fallbacks: --missing-position;
}
Without a corresponding @position-try definition, the named option cannot provide the intended custom placement.
Expecting Fallbacks to Always Prevent Overflow
If no candidate position fits, the element may still overflow. Fallbacks do not guarantee that every layout will fit.
Ignoring Writing Modes
Logical flips follow writing mode and direction. Their physical effect may differ between horizontal and vertical writing systems.
Assuming Universal Browser Support
CSS Anchor Positioning is not consistently available across all browsers. Provide conventional positioning fallbacks where needed.
Important Considerations
Keep the following points in mind when using position-try-fallbacks:
- It defines alternative positions for anchor-positioned elements.
- It is part of CSS Anchor Positioning.
- Its initial value is
none. - The property is not inherited.
- It applies to absolutely positioned elements.
- Fallback options can use built-in flips or custom named positions.
flip-blockcreates a block-axis alternative.flip-inlinecreates an inline-axis alternative.flip-startchanges applicable start and end directions.- Comma-separated options define separate alternatives.
- Space-separated flip keywords can form a combined alternative.
- Custom fallback positions are defined using
@position-try. - Custom fallback names begin with two hyphens.
- Built-in and custom fallback options can be combined in one list.
- The preferred position is defined separately using anchor-positioning properties.
position-anchorcan select the default anchor.position-areacan define the preferred anchor-relative area.position-try-ordercontrols how candidate positions are prioritized.- The
position-tryshorthand sets both fallback options and selection order. - The browser evaluates candidates against applicable overflow constraints.
- Under normal ordering, the preferred position is used when it fits.
- Fallback positions are conditional rather than permanent.
- Fallbacks do not guarantee that every element will fit.
- Writing mode and direction affect logical flip behavior.
- Browser support varies across anchor-positioning features.
- Provide conventional positioning fallbacks when needed.
- Test anchored elements near viewport boundaries.
- Test layouts with different text lengths and zoom levels.
- Maintain accessible keyboard interactions and logical document order.
Browser Support
The CSS position-try-fallbacks 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-order, 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-fallbacks.
Use feature queries and conventional positioning fallbacks when supporting browsers without the required anchor-positioning features.
Specifications
The position-try-fallbacks property is defined in CSS Anchor Positioning Module Level 1.
CSS Anchor Positioning Module Level 1
The specification defines built-in fallback options, custom fallback references, and how alternative placements participate in position selection.
For additional documentation and examples, consult MDN Web Docs.
