CSS align-self Property

You are Here:

CSS align-self Property

CSS align-self property specifies the alignment for the selected flex item inside the flexible container.

Note: CSS align-self property overrides the CSS align-items property.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> h2+div{ display: flex; align-items: flex-start; -webkit-align-items: flex-start; height: 200px; border: 1px solid #000; } h2+div > div{ border: 1px solid #267326; padding: 10px 0; margin: 10px; width: 90px; -webkit-flex: 1; /* Safari 6.1+ */ flex: 1; } #parent > div:nth-child(2){ -webkit-align-self: auto; align-self: auto; } #parent1 > div:nth-child(2){ -webkit-align-self: stretch; align-self: stretch; } </style> </head> <body> <h1>CSS flex-grow Property</h1> <h2>align-self: auto;</h2> <div id="parent"> <div>Div 1</div> <div>Div 2</div> <div>Div 3</div> </div> <h2>align-self: stretch;</h2> <div id="parent1"> <div>Div 1</div> <div>Div 2</div> <div>Div 3</div> </div> </body> </html>

Syntax

Using CSS

element{ align-self: center; }

Using Javascript

object.style.alignSelf="center";

Animatable

Yes, align-self property is animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS align-self property is auto.

Property Value

The following table provides a list of values for CSS align-self property.

ValueExplanation
autoThe element will inherits from it parent. If it has no parent container, then the default value is stretch.
stretchThe element is placed to fit the container.
centerThe element is placed at the center of the container.
flex-startThe element is placed at the beginning of the container
flex-endThe element is placed at the end of the container
baselineThe element is placed at the baseline of the container

Using JavaScript

In the following example, we will demonstrate how to change the CSS align-self property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> #parent{ display: flex; align-items: flex-start; -webkit-align-items: flex-start; height: 200px; border: 1px solid #000; } #parent > div{ border: 1px solid #267326; padding: 10px 0; margin: 10px; width: 90px; -webkit-flex: 1; /* Safari 6.1+ */ flex: 1; } </style> </head> <body> <h1>CSS align-self Property</h1> <div id="parent"> <div>Div 1</div> <div>Div 2</div> <div>Div 3</div> </div> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementById("parent").firstElementChild; function myFunction(){ x.style.alignSelf = "center"; x.style.WebkitAlignSelf= "center"; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author