What CSS technique helps you align items evenly with space around them?
By GetItFullyβ’β’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 |





