CSS margin playground

Explore margin with interactive controls for all sides, per-side, or per-axis spacing, switch units, compare physical and logical properties, and use auto to push or center the block.

Ask AI

CSS margin playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
margin
HTML
<div class="margin-demo">
  <div class="margin" dir="ltr">
    margin
  </div>
</div>
CSS
.margin-demo {
  min-block-size: 20rem;
  background-color: #f3f4f6;
}

.margin {
  display: grid;
  place-items: center;
  inline-size: max-content;
  padding: 1rem;
  border: 1px dashed #f59e0b;
  background-color: #ffffff;
  margin: 24px;
}