Favorites

CSS <overflow-position> Data Type

<overflow-position>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <overflow-position> data type is the keyword safe or unsafe, used with alignment properties to decide what happens when an item overflows.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The <overflow-position> CSS data type represents the keywords safe and unsafe, which control what the box alignment properties do when an item is larger than the space it is being aligned in. It is used as an optional modifier in front of a position keyword in properties such as align-items, align-self, align-content, justify-content, justify-items and justify-self, for example align-items: safe center.

The problem it solves is data loss. When an item is centred inside a container that is too small for it, the item overflows equally on both sides. The part that sticks out on the start side (the top or left in most layouts) ends up outside the scrollable area, so the user cannot scroll to it and that content becomes unreachable. With safe, the browser notices the overflow and switches to start alignment instead, so the item overflows only on the end side, where it can still be scrolled into view.

unsafe tells the browser to always honour the requested alignment, even if that means some content becomes unreachable. If neither keyword is given, the browser uses a default that is somewhere between the two: it behaves like unsafe in most cases but may prevent content from overflowing a scroll container's start edge. Using safe explicitly is a simple way to make centred layouts robust when content size is unknown, such as with user-generated text or translated labels.

Examples:

/* Centre items, but fall back to start if they overflow */
.toolbar {
  display: flex;
  justify-content: safe center;
  overflow-x: auto;
}

/* Vertically centred column that never hides its top */
.panel {
  display: flex;
  flex-direction: column;
  align-items: safe center;
}

/* Explicitly keep the requested alignment */
.hero-title {
  justify-self: unsafe center;
}

The <overflow-position> keywords can only be combined with <content-position> and <self-position> values such as center, start and end; they cannot be used with normal, stretch or baseline values.

Interactive Demo

Short
A much wider item than its box
The dashed box is 150px wide.
Demo Code
HTML Code
<div class="demo-element">
	<div>Short</div>
	<div>A much wider item than its box</div>
</div>
<small class="demo-note">The dashed box is 150px wide.</small>
CSS Code
.demo-element > div {
	padding: 6px 8px;
	background: #f72585;
	color: #fff;
	font-size: 13px;
	white-space: nowrap;
}
.demo-note {
	display: block;
	margin: 6px 0 0;
	font-size: 12px;
	color: #666;
}
.demo-element {
	display: flex;
	flex-direction: column;
	gap: 6px;
	width: 150px;
	margin-left: 75px;
	padding: 6px 0;
	background: #f4f4f4;
	outline: 2px dashed #4361ee;
	align-items: center;
}

Syntax

<overflow-position> = unsafe | safe

Values

  • safeIf the item overflows the alignment container, the item is aligned as if the alignment were start, so that no content is pushed out of reach.
  • unsafeThe requested alignment is always honoured, even if the item overflows the alignment container and some content becomes unreachable.

Example

<div class="wrap">
<h1>CSS &lt;overflow-position&gt; examples</h1>
<div class="cols">
<div>
<div class="label">align-items: unsafe center</div>
<div class="container unsafe">
<div class="item">START of this wide item</div>
</div>
</div>
<div>
<div class="label">align-items: safe center</div>
<div class="container safe">
<div class="item">START of this wide item</div>
</div>
</div>
</div>
<p class="note">With unsafe, the red start of the item is cut off and cannot be scrolled to. With safe, it falls back to start alignment.</p>
</div>
/* Compares safe and unsafe centring of an oversized item */
* { box-sizing: border-box; }

body {
  margin: 24px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: #f7f9fc;
  color: #102a43;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
}

h1 {
  font-size: 20px;
  margin: 0 0 16px;
}

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.container {
  display: flex;
  flex-direction: column;
  width: 200px;
  height: 160px;
  border: 2px solid #94a3b8;
  border-radius: 8px;
  background: #fff;
  overflow: auto;
}

.unsafe { align-items: unsafe center; }
.safe { align-items: safe center; }

.item {
  flex: none;
  width: 300px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #ef4444 0 20%, #2563eb 20%);
  color: #fff;
  font-weight: 600;
}

.note {
  margin-top: 16px;
  font-size: 13px;
  color: #486581;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS overflow-position data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.

This data type is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.