# right

> The `right` CSS property specifies the horizontal offset of a positioned element from the right edge of its containing block.

## How do I position an element in the top right corner with CSS?

The property that sets the distance between the right edge of an element and the right edge of its containing block. With 'absolute' or 'fixed' `position` it places the element in its nearest positioned ancestor or the viewport, while with 'relative' it shifts it from its normal place.

- Topic: Positioning
- Type: property
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```css
.dialog {
  position: relative;
}
.close {
  position: absolute;
  right: 8px;
}
```

Right:

```css
.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: absolute` with a positioned parent and `top` plus `right`.
- Layouts that support right-to-left text use `inset-inline-end` instead of `right`.
- 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.

## Related cards

- [position](https://wonderium.dev/css/position.md)
- [left](https://wonderium.dev/css/left.md)
- [inset](https://wonderium.dev/css/inset-property.md)
- [Logical Properties](https://wonderium.dev/css/logical-properties.md)
- [\[dir\]](https://wonderium.dev/html/dir.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/right
- Last updated: 2026-11-25
