Learn CSS daily

Generate Your Own Playground

Type any CSS property and get a live, editable playground instantly.

scroll-margin-inline-start
.container {
  display: flex;
  overflow-x: auto;
  width: 300px;
  border: 1px solid #ccc;
  padding: 10px;
}

.item {
  min-width: 100px;
  margin-right: 10px;
  background-color: #f0f0f0;
  padding: 20px;
  border: 1px solid #999;
}

.scroll-target {
  scroll-margin-inline-start: 50px;
  margin-top: 20px;
  padding: 10px;
  background-color: #e0e0ff;
  border: 1px solid #000;
  width: 200px;
} 
.scroll-target:focus {
  outline: 2px dashed #ff0000;
}

The 'scroll-margin-inline-start' property sets the margin that is applied to the start of a scrollable area when the element is scrolled into view. This property is particularly useful for creating space around an element when it is focused or scrolled into the viewport, improving the visual layout and accessibility of content in a horizontal or inline context.

scroll-margin-inline-end
.container {
  display: flex;
  overflow-x: auto;
  width: 300px;
  border: 2px solid #000;
}

.item {
  min-width: 100px;
  height: 100px;
  background-color: lightblue;
  margin-right: 10px;
  scroll-margin-inline-end: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.item:last-child {
  scroll-margin-inline-end: 0;
}

The 'scroll-margin-inline-end' CSS property defines the margin that is applied to the end of an element when it is scrolled into view. This margin helps to create space between the element and the edge of the viewport, enhancing the visual experience during scrolling. It is particularly useful for ensuring that elements do not get too close to the viewport edges, especially in horizontally scrolling contexts.

scroll-margin-inline
.container {
  height: 200px;
  overflow-y: scroll;
  border: 1px solid #ccc;
}

.item {
  padding: 20px;
  border: 1px solid #000;
  margin: 10px 0;
}

#target {
  scroll-margin-inline: 20px;
  background-color: yellow;
  margin: 10px 0;
}

The 'scroll-margin-inline' property in CSS defines the margin that will be applied to an element when it is scrolled into view. This margin is applied to the inline start and end of the element, allowing for better control over the positioning of the element when it is focused or targeted by scrolling actions. It helps create a more visually appealing layout by ensuring that elements do not stick too closely to the edges of their scroll container.

scroll-margin-block-start
.container {
  height: 200vh;
  background-color: #f0f0f0;
  padding: 20px;
} 

.header {
  font-size: 24px;
  margin-bottom: 20px;
} 

.target {
  background-color: #4CAF50;
  color: white;
  padding: 20px;
  margin-top: 100px;
  scroll-margin-block-start: 50px;
  scroll-margin-top: 50px; /* Added for compatibility with block-start */
} 

.content {
  background-color: #ffffff;
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

The 'scroll-margin-block-start' property in CSS defines the margin that will be applied to the start of a block container when it is scrolled into view. This is particularly useful for creating space between the top of the viewport and the element being scrolled to, enhancing the visibility and aesthetics of the layout.

scroll-margin-block-end
body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.spacer {
    height: 100vh;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section {
    height: 100vh;
    background-color: #4CAF50;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    scroll-margin-block-end: 50px; /* This creates space below the section when scrolled into view */
}

#section1 {
    background-color: #2196F3;
}

#section2 {
    background-color: #FF9800;
}

#section3 {
    background-color: #F44336;
}

The 'scroll-margin-block-end' CSS property defines the margin area on the block-end side of an element when it is scrolled into view. This property is particularly useful for creating space between the element and the viewport edge, enhancing the user experience during scrolling, especially in single-page applications or sections with anchor links.