align-self

Definition

align-self will override the value provided on the align-items CSS property.

.element {
  align-self: stretch;
}

Syntax

.card {
  display: grid;
}

.card__cta {
  align-self: center;
}

align-self works across flexbox and grid layouts to position tracks or individual items along the main or cross axis.

Values

  • start / end: align content to the logical start or end edge (writing-mode aware).
  • center: center items or tracks along the axis.
  • stretch: expand items to fill the available space when allowed.
  • baseline: line up first baselines for tidy typography.
  • auto: inherit the parent container setting unless overridden.

Practical Examples

.pricing {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-items: center;
  gap: 2rem;
}

.pricing__cta {
  align-self: center;
}

Targeted alignment keeps each call-to-action centered without disturbing sibling cards.

HTML

Inherited alignment

Override with align-self: center

Code
<div class="grid gap-4 sm:grid-cols-2">
  <div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
    <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Inherited alignment</p>
    <div class="grid h-48 gap-3 rounded-md border border-dashed border-slate-300 bg-slate-50 p-3" style="display: grid; align-items: start; justify-items: start;">
      <button class="rounded-full bg-slate-900 px-4 py-2 text-sm font-semibold text-white">Default</button>
      <button class="rounded-full bg-slate-100 px-4 py-2 text-sm font-semibold text-slate-700">Also start</button>
    </div>
  </div>
  <div class="space-y-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm">
    <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Override with align-self: center</p>
    <div class="grid h-48 gap-3 rounded-md border border-dashed border-slate-300 bg-slate-50 p-3" style="display: grid; align-items: start; justify-items: start;">
      <button class="rounded-full bg-slate-900 px-4 py-2 text-sm font-semibold text-white">Default</button>
      <button class="rounded-full bg-sky-500 px-4 py-2 text-sm font-semibold text-white" style="align-self: center;">Centered</button>
    </div>
  </div>
</div>

Tips & Best Practices

  • Align on the container first, then reach for *-self overrides only when a child needs unique treatment.
  • Prefer logical keywords (start, end) over physical directions for better localisation.
  • Combine alignment with gap to manage spacing without extra wrapper elements.
  • Use auto to fall back to the container alignment and reduce redundant declarations.

Accessibility & UX Notes

Predictable alignment lowers cognitive load and lets keyboard users tab through content without unexpected jumps. Maintain visible focus indicators and ensure stretched components still provide generous hit areas.

Browser Support

align-* and justify-* properties are well supported. place-* shorthands require Chrome 59+, Edge 79+, Firefox 66+, Safari 12.1+.

  • gap for consistent spacing between tracks or items.
  • justify-content, align-items, and place-content to coordinate both layout axes.
  • flex-direction and grid-auto-flow influence which axis is treated as main vs. cross.

Related posts