<body>
    <div class="sticky">This item will stick</div>
</body>
body {
    background: #1a1a1a;
    height: 200vh;
    margin: 0;
    padding-top: 150px;
}

.sticky {
    background: #ff4163;
    height: 100px;
    width: 100px;
    position: sticky;
    top: 50px;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.