<div class="container">
  <div class="box"></div>
</div>
.box {
  position: sticky;
  top: 0px;
}

/* Base styles */

.box {
  width: 100px;
  height: 100px;
  background: lightblue;
}

.container {
  padding: 10px;
  height: 400px;
  border: 3px solid black;
}

html, body {
  height: 200%;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.