right
Example
.dialog {
position: relative;
}
.close {
position: absolute;
right: 8px;
}.dialog {
position: relative;
}
.close {
position: absolute;
inset-inline-end: 8px;
}inset-inline-end sits on the right in left-to-right text and flips to the left in right-to-left text.
Common mistakes
- The element sticks to the page's right edge because the parent isn't positioned.
- A close button stays on the right in right-to-left layouts where it should flip.
Key points
- Corner placement uses
position: absolutewith a positioned parent andtopplusright. - Layouts that support right-to-left text use
inset-inline-endinstead ofright. - Fixed elements on the right account for the scrollbar and safe area insets.
Interview questions
Why is right: 0 not working?
The element needs a position other than 'static', and for 'absolute' an ancestor that is positioned.
What happens if I set both left and right?
With 'auto' width the element stretches between both; with a fixed width, the start side wins, which is left in left-to-right text.
What is the logical version of right?
inset-inline-end, which follows the text direction.