Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

align-self: override alignment for one item

Change an individual flex or grid item without changing its siblings.

Version: CSS Modules

Syntax

align-self: flex-end;

Place align-self on the item, not on its container. In flexbox it acts along the cross axis; in grid it acts along the block axis within the item’s grid area. auto normally uses the parent’s align-items value for these items. This is not a general command that centers every ordinary block: the formatting context determines whether and how the property applies.

Values such as center, start, end, flex-start, flex-end and stretch choose the item’s own alignment. first baseline and last baseline participate in baseline alignment groups rather than aligning geometric centers. Stretch still respects sizing constraints. A cross-axis auto margin can consume the free space before alignment is applied, making an apparent align-self failure a margin issue. safe and unsafe qualify overflow handling for positional alignment.

In the example, both children are 20px high in a 100px row whose shared alignment is center. The ordinary child starts at 40px, while the flex-end override starts at 80px. Returning the second item to auto places both at 40px. Finally, margin-top: auto places the second at 80px even with align-self: flex-start, demonstrating the precedence directly.

Examples

const row = document.createElement('div');
row.style.cssText = 'display:flex;align-items:center;width:200px;height:100px';
const a = document.createElement('div'), b = document.createElement('div');
for (const item of [a,b]) item.style.cssText = 'width:40px;height:20px';
b.style.alignSelf = 'flex-end'; row.append(a,b); document.body.append(row);
const top = el => Math.round(el.getBoundingClientRect().top - row.getBoundingClientRect().top);
console.log('override top:', top(a), top(b));
b.style.alignSelf = 'auto';
console.log('auto top:', top(a), top(b));
b.style.alignSelf = 'flex-start'; b.style.marginTop = 'auto';
console.log('auto margin top:', top(b));
row.remove();

Result

override top: 40 80
auto top: 40 40
auto margin top: 80

Executed in Chromium 157.0.8103.51. The example checks flex item geometry, not absolute-positioned or anchor-center behavior. Inspect the axis, available space, margins and explicit size before changing unrelated layout properties.

Sources