CSS anchor-name Property
Description
The CSS anchor-name property is part of the CSS Scroll Snap Module and is primarily used to give a scroll container a named anchor that can be referenced for linking and navigation purposes. It allows sections of content within a scrollable container to be targeted, often in combination with smooth scrolling or programmatically controlling scroll positions.
Think of it as a way to assign a label or identifier to a scrollable element so that it can be referenced elsewhere in CSS or JavaScript. This is especially useful in creating scroll snapping layouts or single-page navigation patterns, where you want certain content areas to align neatly or respond to anchor links.
When an element has an anchor-name, it can be scrolled into view automatically when that name is used in a scroll-snap context or in fragment identifiers in URLs. For example, a user might click a link like #section3, and the browser can scroll the container so that the element with anchor-name: section3 becomes visible.
Essentially, the property provides a semantic handle to scrollable content, decoupling the scroll behavior from structural IDs or classes. It’s a way to name scroll positions explicitly, improving accessibility, navigation, and dynamic content control.
Key concepts:
- Useful for scroll-snapping containers or smooth-scrolling interfaces.
- Works as a reference point for linking to specific parts of a scrollable container.
- Helps organize content for navigational purposes without relying solely on HTML
idattributes.
Definition
- Initial value
- none
- Applies to
- All elements that generate a principal box
- Inherited
- no
- Computed value
- as specified
- Animatable
- yes
- JavaScript syntax
- object.style.anchorName
Syntax
.anchor-element { anchor-name: --my-anchor-name; }Values
- noneThe default value. The element is not an anchor and cannot be referenced by other elements.
- <dashed-ident>A user-defined identifier. It must start with two dashes (e.g., --tooltip-anchor, --main-menu). This name is then used by the anchor() or anchor-size() functions on a positioned element.
- initialSets the property to its default value (none).
- inheritInherits the value from the parent element.
Example
Browser Support
The following information will show you the current browser support for the CSS anchor-name property. Hover over a browser icon to see the version that first introduced support for this CSS property.
Desktop





Tablets & Mobile





