Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS align-content Property

Posted in CSS Tutorial
Updated on Jul 14, 2024
By Mari Selvan
👁️ 18 - Views
⏳ 4 mins
💬 1 Comment
CSS align-content Property

Photo Credit to CodeToFun

🙋 Introduction

The align-content property in CSS is used to control the alignment of flexible container's lines within the flex container when there is extra space on the cross-axis.

It is applicable only to flex containers, allowing developers to specify how multiple lines are spaced apart from each other within a container.

💡 Syntax

The syntax for the align-content property is simple. It can be applied to any flex container.

Syntax
Copied
Copy To Clipboard
.container {
  align-content: value;
}

🎛️ Default Value

The default value of the align-content property is stretch.

🏠 Property Values

ValueDescription
stretchLines stretch to take up the remaining space.
centerLines are packed toward the center of the flex container.
flex-startLines are packed toward the start of the flex container.
flex-endLines are packed toward the end of the flex container.
space-betweenLines are evenly distributed in the flex container with the first line at the start and the last line at the end.
space-aroundLines are evenly distributed with equal space around each line.
space-evenlyLines are evenly distributed with equal space between them.

📄 Example

In this example, we'll demonstrate how to use the align-content property to center multiple lines of flex items within a flex container.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS align-content Example</title>
  <style>
    .container {
      display: flex;
      flex-wrap: wrap;
      height: 200px;
      align-content: center;
      border: 1px solid #000;
    }
    .item {
      flex: 0 0 30%;
      margin: 5px;
      height: 50px;
      background-color: lightblue;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>
<body>
  <h1>Flex Container with Centered Content</h1>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
    <div class="item">5</div>
    <div class="item">6</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The align-content property is widely supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is important to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The align-content property is an essential tool for web developers working with flexbox layouts. It provides control over the alignment of flex lines within a container, ensuring that the layout remains visually appealing and consistent. Experiment with different values of the align-content property to see how it can enhance the layout of your flex containers.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy