Back to library
🎨CSScssbeginner

Flexbox Centering

Center elements both horizontally and vertically using flexbox

layoutflexboxcentering

Code

1.center-flex {
2  display: flex;
3  justify-content: center;
4  align-items: center;
5}
6
7/* With gap for multiple children */
8.center-flex-with-gap {
9  display: flex;
10  justify-content: center;
11  align-items: center;
12  gap: 1rem;
13}
14
15/* Column direction */
16.center-flex-column {
17  display: flex;
18  flex-direction: column;
19  justify-content: center;
20  align-items: center;
21  gap: 1rem;
22}

Quick Tips

  • Click the "Copy" button to copy the code to your clipboard
  • This code is production-ready and can be used in your projects
  • Check out related snippets below for more examples

Build Your Own Snippet Library

Organize your team's code snippets with Snippetly. Share knowledge and boost productivity across your organization.