Position-visibility - CSS Property

position-visibility

Summary of characteristics of the position-visibility property

Quick description
Defines whether the positioned element is visible or not, in the context of anchoring positioning.
Status
Standard
Applies to
Elements positioned in fixed or absolute.
Predefined values
anchors-visible | always | anchors-valid | no-overflow
Percentages
Not applicable.
Initial value
anchors-visible (1)
Inherited by default
No.
Discrète: during an animation, the position-visibility property passes from one value to another without transition.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Anchor Positioning
Document status: WD (Working Draft)

(1) Actually, browsers use always as the initial value.

Syntax diagram of position-visibility.

position-visibility - Syntax DiagramSyntax diagram of the position-visibility CSS property. always always anchors-valid anchors-valid anchors-visible anchors-visible no-overflow no-overflowposition-visibility:;position-visibility:;
Syntax diagram of the position-visibility property.
The links in the diagram provide more details about the values.
Download the diagram.

Description of the position-visibility property.

⚠
It still behaves a bit unpredictably on some browsers.

The property position-visibility comes into play in the case of an element positioned by anchoring, that is, relative to another element called the anchor. For more information on anchor positioning, we invite you to check out the pages on anchor-name, position-anchor, or position-area.

The position-visibility property makes the positioned element disappear when its anchor is no longer visible, either because it has scrolled out of view or because it is hidden by another absolutely positioned element.

Let's remember that there is a position-try property and an at-rule with the same name, which often allow you to handle the display of the positioned element in a more subtle way.


Check out the page anchor-name for a tutorial on anchor positioning.

Values for position-visibility.

  • position-visibility: always;

    The property has no effect. The positioned element is always displayed (unless it ends up outside the viewport).

    ⚓
    Text positioned
    above the anchor.
    Text positioned
    below the anchor.
  • position-visibility: anchors-visible;

    `anchors-visible activates the hiding of positioned text in the following cases:

    • The anchor is out of the viewport.
    • The anchor is hidden by another positioned element.
    • The anchor itself is hidden (property visibility:hidden or display:none).

    Slowly scroll the container down, the text positioned above the anchor disappears when the image is no longer visible at all. When scrolling the page up, it’s the text above the anchor that disappears. You can also click the "Hide the anchor" button.

    ⚓
    Text positioned
    above the anchor.
    Text positioned
    below the anchor.
  • position-visibility: anchors-valid; ⚠

    If the anchor associated with this element doesn't match a valid box, the positioned element is hidden.
    Browsers still handle this value very poorly.

    ⚓
    Text positioned
    above the anchor.
    Text positioned
    below the anchor.
  • position-visibility: no-overflow;

    The element is completely hidden as soon as it starts to leave the viewport. To see this, gently scroll the container down: as soon as the positioned element begins to go out of the viewport, it disappears.

    If the element is positioned above the anchor, it's when it disappears upwards; if it's placed below the anchor, it's when the element disappears downwards. It's the same thing for positioning to the left or right of the anchor.

    ⚓
    Text positioned
    above the anchor.
    Text positioned
    below the anchor.


    It is possible to combine the three values anchors-visible, no-overflow, and anchors-valid.

  • position-visibility: initial; (anchors-visible (1)) position-visibility: inherit; position-visibility: revert; position-visibility: revert-layer; position-visibility: revert-rule; position-visibility: unset;

    See the following pages for more details: initial, inherit, revert, revert-layer, revert-rule, unset.

Simulator.

The simulator sets an anchor on the image; the positioned text is placed relative to this anchor. You can change the value assigned to position-visibility and check how the positioned text behaves.

For the anchors-visible value, lower the container height, or use the "Hide anchor" button.
For the no-overflow value, reduce the container width. As soon as the positioned text can no longer be fully displayed, it disappears completely.

position-visibility :
⚓
Positioned text
This text shows or hides depending on the value assigned
to the property position-visibility.

Browsers compatibility with position-visibility.

Browsers now handle anchor positioning correctly, with a few exceptions.

  • It seems that all elements involved in positioning (anchor and positioned elements) must have an ID, even if it isn’t used..
  • There are behavioral differences between position:absolute and position:relative that the standard doesn’t talk about.
Column 1
General support for anchor positioning.
Column 2
Support for the position-visibility property (Anchor positioning).

Notes:

(1) Samsung Internet does not support the position-anchor property with the value normal. It also doesn't fully support the 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.

1
Anchor
positioning
2
position-visibility
property
Estimated overall support.
86%
71%

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-visibility 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 functions anchor() and anchor-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.

    Regarding position-visibility First presentation of the property position-visibility (anchoring positioning).
    WD
    June 29, 2023
    Working Draft.
    CR
    PR
    REC

See also about anchor positioning.

The properties, functions, and at-rule that manage anchor positioning are grouped in CSS Anchor Positioning. These are the ones listed below.

Properties:

anchor-name
Sets an ID for the item, which can then become an anchor, in the context of anchor positioning.
anchor-scope
Defines the scope of the property anchor-name.
position-anchor
Defined in relation to which anchor the element should be positioned.
position-area
Defines how an element is positioned relative to the anchor (above, beside, etc.).
position-try
Shorthand property that summarizes the values for position-try-fallbacks and position-try-order.
position-try-fallbacks
Specifies a list of positions for the positioned element (anchoring positioning) so that the browser can choose the one that is most suitable at any given moment, taking into account scrolls or zooms.
position-try-order
Defines a different order for the values listed by position-try-fallbacks.
Position-visibility
Defines whether the positioned element is visible or not, in the context of anchoring positioning.

Functions:

anchor()
Returns the position of one of the edges of the element designated as the anchor (anchor-based positioning).
anchor-size()
Returns the size (height or width) of the element designated as the anchor (anchor-based positioning).

At-rules:

@position-try
Defines a set of rules for each anchor position and gives them a name (anchoring positioning).