What CSS technique helps you align items evenly with space around them?
•9 min read
Here’s a complete explanation with an example 👇
🎯 Question:
What CSS technique helps you align items evenly with space around them?
✅ Answer:
The CSS technique is using Flexbox with the property
👉 justify-content: space-around;
This distributes items evenly along the main axis, with equal space around each item — meaning equal spacing between items and at the container’s edges.
💻 Example Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Space Around Example</title>
<style>
.container {
display: flex;
justify-content: space-around;
background-color: #f3f3f3;
padding: 20px;
}
.box {
background-color: #4CAF50;
color: white;
padding: 20px;
width: 100px;
text-align: center;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
</div>
</body>
</html>
JavaScript🧠 How It Works:
display: flex;activates Flexbox layout.justify-content: space-around;distributes equal space before, between, and after the items.
If you want different spacing options:
space-between→ equal space between items (no space at edges).space-evenly→ equal space everywhere (including edges and between items).
🏁 Summary
| Property | Description |
|---|---|
justify-content: space-around; | Even space around items |
justify-content: space-between; | Even space only between items |
justify-content: space-evenly; | Equal space between and around items |


