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:

  • length: This property refers to the values defined with length units like em, px, rem, vh, etc.
  • Global_Values: This property refers to the global values like inherit, initial, unset, etc.

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.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Supported Browsers:

  • Firefox
  • Chrome
  • Opera
  • Edge



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.