Position-try-fallbacks - CSS Property
Summary of characteristics of the position-try-fallbacks property
fixed or absolute.none | flip-block | flip-inline | flip-start | flip-x | flip-ynoneDiscrète: during an animation, the position-try-fallbacks property passes from one value to another without transition.Per grammar: serialization in the order of syntax.Syntax diagram of position-try-fallbacks.
position-try-fallbacks property.The links in the diagram provide more details about the values.
Download the diagram.
In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:
--idis an identifier (which must start with a double dash) created by@position-try.positionis a position (identical to those ofposition-area.
Description of the position-try-fallbacks property.
Anchor positioning involves placing an element relative to another (see Anchor positioning). The element used as a reference (the anchor)
gets an ID (via anchor-name). This can then be used on other elements to position them with position-anchor.
Positioning can be precise: to the right, above, etc., of the anchor using the position-area property. You can also set an alternative position
with position-try-fallbacks in case the positioned text disappears before its anchor, for example due to scrolling.
In the example below, as you scroll down the page, you'll notice that the positioned element is first above the anchor, then, when scrolling starts to make it disappear, it goes below the anchor. Until scrolling back up makes it disappear at the bottom of the window, it goes back above the anchor.
The default position of the element is still set by position-area. If the positioned element is fully visible, considering scrolling, zooms, etc.,
the position-try-fallbacks property is ignored.
By using position-try-fallbacks correctly, it's possible to make the positioned element stay visible as long as possible, even when scrolling or zooming on the page.
See also the shorthand property position-try, as well as the anchor-name property, which gives a summary of useful properties in anchor positioning.
Values for position-try-fallbacks.
- position-try-fallbacks: none;
With the value
none, the propertyposition-try-fallbackshas no effect. - position-try-fallbacks: bottom;
A value or a series of values accepted by the
position-areaproperty. If multiple values are specified, they must be separated by a comma (currently, browsers do not handle series of values). One of these values is applied, in order, to position the element.Scroll down this page until the text is at the top of the screen. You'll then see it pass under the anchor.
⚓Positioned elementposition-area:top;
position-try-fallbacks:bottom; - position-try-fallbacks: flip-block; position-try-fallbacks: flip-y;
The
flip-blockvalue reverses the positioning between the start and end of a block. It also swaps the start and end block margin values. It is sensitive to the writing mode of the language used.
For example, for latin languages,flip-blockswaps the positions above and below the anchor.flip-yis the same but isn’t affected by the language writing mode.⚓Positioned elementposition-area:top;
position-try-fallbacks:flip-block; - position-try-fallbacks: flip-inline; position-try-fallbacks: flip-x;
flip-inlineflips the start and end positions of an element's lines. It also swaps the start and end line margin values. So, this value depends on the language's writing mode.
For latin languages,flip-inlineflips left and right.flip-xmakes the same changes, without being sensitive to the writing direction of the language.To see how it works, reduce the width of your browser window until the right edge reaches the positioned text.
On a phone or a device with a small screen, the small window width makesposition-try-fallbacksactivate immediately.⚓Positioned elementposition-area:right;
position-try-fallbacks:flip-inline; - position-try-fallbacks: flip-start;
The
flip-startvalue swaps thestartvalues with each other, and theendvalues with each other. For example, it changes the positioned element fromblock-starttoinline-startand fromblock-endtoinline-end. This also works if the values are given in physical values or in XY values.Scroll down the page to see how it works on the first example. You'll need to reduce the window width for the second example.
On a phone or a device with a small screen, the small window width prevents it from working.⚓⚓Positioned elementposition-area:top
position-try-fallbacks:flip-start;Positioned elementposition-area:bottom
position-try-fallbacks:flip-start; - position-try-fallbacks: --id1, --id2;
--id1and--id2are identifiers defined by the@position-trydirectives. They can group several properties, like margins, for example.
Multiple identifiers can be listed, separated by commas.In the example below, the positioned element first moves to the right of the anchor, then, if you shrink the window width, it moves below the anchor.
On a phone or a device with a small screen, the narrow window width interferes with how it works: the positioned text goes straight to--pos2, without going through--pos1.⚓Positioned elementposition-area:top;
position-try-fallbacks:--pos1,--pos2; - position-try-fallbacks: initial; (
none) position-try-fallbacks: inherit; position-try-fallbacks: revert; position-try-fallbacks: revert-layer; position-try-fallbacks: revert-rule; position-try-fallbacks: unset;Links to the presentation of these different values:
initial,inherit,revert,revert-layer,revert-rule,unset.
Animation of the position-try-fallbacks property.
The position-try-fallbacks property can be animated, but the visual result isn't very interesting because the property isn't always active.
The property animates in a discrete way, meaning it jumps from one value to another without any transition.
Browsers compatibility with position-try-fallbacks.
The property position-try-fallbacks is well supported by modern browsers.
position-try-fallbacks property allowing the specification of multiple positions for anchoring positioning.Notes:
(1) Samsung Internet does not support the position-anchor property with the value normal.anchor-visibility property.
(2) Android browser does not support the position-anchor property with the value normal.
It also doesn't fully support the anchor-visibility property.
(3) Doesn't fully support the anchor-visibility property.
(4) Firefox does not allow animation of the anchor() and anchor-size() functions.
It does not fully support the anchor-visibility property.
(5) Opera does not support the position-anchor property with the value normal.
It also doesn't fully support the anchor-visibility property.
positioning
position-try-fallbacksproperty
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Androïd Brower

Chrome

Chrome pour Androïd

Edge

Firefox

Firefox pour Androïd

KaiOS Browser

Opéra

Safari

Safari sur IOS

Opéra mini
Historic of the position-try-fallbacks property.
-
CSS Anchor Positioning - Level 1
Absolute positioning relative to the page or screen can prove to be limited when you want to position an element relative to another.
This specification describes the properties necessary to achieve this, as well as the functionsanchor()andanchor-size()that allow you to set the position and dimensions of an element based on another.
It also describes how to test several positioning possibilities to adapt to the context, particularly to the state of the page scrolling.Regardingposition-try-fallbacksFirst presentation of the propertyposition-try-fallbacks.June 29, 2023Working Draft.
See also, about anchor positioning.
Anchor positioning is one of the most interesting features of CSS. All the properties, functions, or directives related to this feature are grouped in the specification CSS Anchor Positioning.
Properties:
anchor-name.position-try-fallbacks and position-try-order.position-try-fallbacks.


