- CSS align-items Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- Example
- Example
- Example with grid
- Example with absolute positioning
- How to align list items vertically in HTML lists with CSS?
- Aligning HTML lists in WordPress
- How to align HTML lists vertically using list-style-position CSS property?
- Vertical align list items with CSS using list-style-position property
- Styling HTML lists furthermore with CSS
- Featured Tutorial
- How to Align a list in HTML?
- Often have questions like this?
CSS align-items Property
Center the alignments for all the items of the flexible element:
More «Try it Yourself» examples below.
Definition and Usage
The align-items property specifies the default alignment for items inside a flexbox or grid container.
- In a flexbox container, the flexbox items are aligned on the cross axis, which is vertical by default (opposite of flex-direction).
- In a grid container, the grid items are aligned in the block direction. For pages in English, block direction is downward and inline direction is left to right.
For this property to have any alignment effect, the items need available space around themselves in the appropriate direction.
Tip: Use the align-self property of each item to override the align-items property.
Default value: | normal |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS3 |
JavaScript syntax: | object.style.alignItems=»center» Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
CSS Syntax
Property Values
Value | Description | Play it |
---|---|---|
normal | Default. Behaves like ‘stretch’ for flexbox and grid items, or ‘start’ for grid items with a defined block size. | Demo ❯ |
stretch | Items are stretched to fit the container | Demo ❯ |
center | Items are positioned at the center of the container | Demo ❯ |
flex-start | Items are positioned at the beginning of the container | Demo ❯ |
flex-end | Items are positioned at the end of the container | Demo ❯ |
start | Items are positioned at the beginning of their individual grid cells, in the block direction | |
end | Items are positioned at the end of the their individual grid cells, in the block direction | |
baseline | Items are positioned at the baseline of the container | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
More Examples
Example
Items are positioned at the beginning of the container:
Example
Items are positioned at the end of the container:
Example
Items are positioned at the baseline of the container:
Example
Items are stretched to fit the container:
Example with grid
Items are aligned at the start of each grid cell in the block direction:
Example with absolute positioning
Items are aligned at the end of each grid cell in the block direction for absolute positioned grid items:
#container <
display: grid;
position: relative;
align-items: end;
>
#container > div position: absolute;
>
How to align list items vertically in HTML lists with CSS?
HTML lists are some of the most used HTML elements in web development, but also in writing page and post content. In WordPress, lists come with some basic default styling applied by the theme. In most of the cases you’ll want to modify the default list styling to meet your design needs. This article will teach you how to style HTML lists using CSS, and make’em look exactly as you imagined. Therefore, the first thing you want to do is align list items vertically.
Aligning HTML lists in WordPress
Are you editing a WordPress theme and styling a HTML list in it? Most importantly, make sure you don’t break the theme by editing the default stylesheet. Also make sure you don’t loose your custom code after updating the theme.
The best practice would be to add your own stylesheet CSS file to the theme or child-theme you are working on. If you haven’t already done that already, read our article on Adding custom CSS files to WP themes first.
How to align HTML lists vertically using list-style-position CSS property?
WordPress theme developers often don’t pay too much attention to styling HTML lists. This makes lists in site content look rather basic. By adding few simple CSS properties to the list style, you can make it stand out in the content.
In many WP themes default vertical list aligment property list-style-position is not set. This property defines the position of list bullet points (•) in relation to the text. If not set, the default value of the list-style-position property will be inside . In that case the whole list (both bullets and text) will be aligned completely to the left. This style makes lists with items that span in two or more lines harder to read. Also, visually the list doesn’t look too good.
Comparison of an unstyled HTML list (left) and a vertically aligned HTML list (right).
Vertical align list items with CSS using list-style-position property
We’ll easily change the HTML list vertical alignment by adding the CSS property list-style-position with the value outside to it. Bullet points will now align absolutely to the left and multi-line list items will align verticaly after the bullets. The list already looks better and it’s easier to read.
Now we can add few more CSS properties tho furthermore improve the HTML list basic formatting. Let’s add some padding to the left of the list to distance a bit the list from the content edge. Further, adding some bottom margin to the list items will improve readability even more.
This is how the CSS properties for HTML list alignment in our example look like:
- and ordered
lists. In our example we styled an unordered HTML list. If you are styling an orderd list replace the ul selector in the code above with the ol selector.
Styling HTML lists furthermore with CSS
This example was just the first step to styling your HTML lists to perfection. Simmilary, by adding a couple more CSS properties to your list CSS style you can achieve much more. You could format your lists into columns or change color and shape of bullet points to make the list stand out even more.
Follow the links below for more advices on styling HTML lists:
Featured Tutorial
The creation of any WP based website, from simple personal blogs over popular web magazines to sophisticated web shops start .
How to Align a list in HTML?
How can someone align a list in the left, right and center in HTML?
Remember, the center tag is deprecated and you should not use it. Instead, use css, like the first example provided by Valentin or the one provided by Uran. I myself put always inline tags as inline-blocks, give them a width, and use margin: 0 auto; to center most of the things horizontally.
Thanks a lot for both of you. Would you please give me an example, Since I’m very new with HTML it would be very helpful to have one.
- green
- blue
- yellow
- Black
- Brown
- green
- blue
- yellow
- Black
- Brown
Thank you ValentineHacker so much for the trick. 🙂 Although that’s not the result that I was looking for, still the trick is so greaaaaaaat. what I want is the lists to be under each other on the right then under each other on the left and under each other on the center, not next to the other, would you tell me how can I do it, please?
@KINGODX thank you so much. I’m very new at HTML, I don’t know how would I use what you are saying to have a the code that you are talking about. 🙁
I want the two lists to be both present, and aligned beneath each other, and that’s how I want the result to looks like on the browser 1—-left 1.green 2.blue 3.yellow 4.Black 5.Brown -green -blue -yellow -Black -Brown 2——Right 1.green 2.blue 3.yellow 4.Black 5.Brown -green -blue -yellow -Black -Brown 3——Center 1.green 2.blue 3.yellow 4.black 5.Brown -green -blue -yellow -black And it seems that the center dont work with float
Often have questions like this?
Learn more efficiently, for free: