Skip to content

is there a way to use anchorName/anchorPosition in stylex? #669

Closed Answered by nmn
lifeiscontent asked this question in Q&A
Discussion options

You must be logged in to vote

Using variables is supported for anchor positioning, but the value of the variable must start with --

e.g.

const anchors = stylex.defineVars({
  myAnchor: '--my-anchor',
});

The generated CSS will now be var(--somehash), but it will resolve to --my-anchor and will work as expected.

You can also do this without defineVars at all and just use a string for anchorName directly:

anchorName: '--my-anchor',

This works and is explicitly supported.


We do not currently have a special case for these properties to avoid wrapping them in var(). This is intentional because you can use variables for those properties.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nmn
Comment options

nmn Jul 28, 2025
Collaborator

Answer selected by lifeiscontent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants