Open In App

CSS scroll-margin-block-start property

The scroll-margin-block-start property is used to set all the scroll margins to the start side of a scroll element at once. This property defines the margin of the scroll snap area at the start of the block dimension that is used for snapping this box to the snap port.

Syntax:



scroll-margin-block-start: length

/* Or */

scroll-margin-block-start: Global_Values

Property values: This property accepts two properties mentioned above and described below:

Note: scroll-margin-block-start doesn’t accept percentage value as the length.



Example: In this example, you can see the effect of scroll-margin-block-start by scrolling to a point partway between two of the “interfaces” of the example’s content.




<!DOCTYPE html>
<html>
<head>
    <style>
        .interfaces {
            width:280px;
            height:300px;
            scroll-snap-align: start none;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 60px;
            color: white;
        }
        .Container {
            width: 300px;
            height:300px;
            overflow-x: hidden;
            overflow-y: auto;
            white-space: nowrap;
            scroll-snap-type: y mandatory;
        }
    </style>
</head>
<body>
    <div class="Container">
        <div class="interfaces" style=
            "background-color: rgb(117, 228, 27);
            scroll-margin-block-start: 80px;">
            Geeks 1
        </div>
        <div class="interfaces" style=
            "background-color: green;
            scroll-margin-block-start: 50px;">
            for 2
        </div>
        <div class="interfaces" style=
            "color: black;
            scroll-margin-block-start: 100px;">
            Geeks 3
        </div>
        <div class="interfaces"
            style="background-color: rgb(60, 184, 126);
            scroll-margin-block-start: 80px;">
            for 4
        </div>
        <div class="interfaces" style=
            "background-color: rgb(30, 253, 30);
            scroll-margin-block-start: 80px;">
            Geeks 5
        </div>
    </div>
</body>
</html>

Output:

Supported Browsers:


Article Tags :