Dev Helpers
← Back

Centre an absolutely positioned layer

Centre an absolutely positioned layer with native CSS. The preview includes a small shared demo stylesheet.

Open this example in the interactive library

Source code

<style>
  .demo {
    position: relative;
    min-height: 5rem;
  }
  .tile {
    position: absolute;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
  }
</style>
<div class="demo"><span class="tile">Centre</span></div>