'What is the difference between margin-block-start and margin-top?

Trying to understand the core difference in usage between the two, but I fail to find an article or doc that details such a comparison. Taking the example provided here, assuming the following:

div {
  background-color: yellow;
  width: 120px;
  height: 120px;
}

.exampleText {
  writing-mode: vertical-lr;
  margin-block-start: 20px;
  background-color: #c8c800;
}
<div>
  <p class="exampleText">Example text</p>
</div>

The difference between this instance, and one in which margin-top is used, is quite small (however visible).

The specifications state that margin-block-start depends on layout model while margin-top refer to the width of the containing block. Would love it if someone could explain it in layman's term.



Solution 1:[1]

The margin-block-start CSS property defines the logical block start margin of an element, which maps to a physical margin depending on the element's writing mode, directionality, and text orientation.

Please run the snippet to see the behavior in action:

document.addEventListener('DOMContentLoaded', event => {
const choice = document.querySelectorAll('.choice');
const target = document.querySelectorAll('.row-target')[0];

choice.forEach(el => el.addEventListener('click', event => {
  choice.forEach(el => el.classList.remove('selected'));
  event.target.classList.add('selected');
  target.setAttribute('style', event.target.innerText);
}));
})
* {
    box-sizing: border-box;
}

#container {
    width: 300px;
    height: 200px;
    display: flex;
    align-content: flex-start;
    flex-direction: column;
    justify-content: flex-start;
    margin-left: 20px;
}

.row {
    height: 33.33%;
    display: inline-block;
    border: solid #5b6dcd 10px;
    background-color: rgba(229,232,252,.6);
    flex-shrink: 0;
}

.row-target {
    border: solid 10px #ffc129;
    background-color: rgba(255,244,219,.6);
}

.transition-all {
    transition: all .3s ease-in;
}

.choice {
background-color: #fff;
    display: flex;
    align-items: center;
    flex-grow: 1;
    position: relative;
    z-index: 1;
    display: block;
    margin: .2em 0;
    width: 100%;
    border: 2px solid #d6dee0;
    border-left: 5px solid #d6dee0;
    font-size: 14px;
    cursor: pointer;
    transition: background-color .2s ease-out,border .2s ease-out;
}

.choice.selected:before {
    opacity: 1;
    right: -1.5em;
}
.choice:before {
    content: '';
    position: absolute;
    top: 50%;
    right: -10px;
    z-index: 1;
    opacity: 0;
    transition: all .2s ease-out;
    transform: translateY(-50%);
    border-left: 10px solid #1b76c4;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
}

.selected {
    border-color: #1b76c4;
    border-left-color: #1b76c4;
    box-shadow: inset 0 2px 2px -2px rgb(0 0 0 / 20%);
    transition: height .5s;
    cursor: text;
}
<table>
<tr>
<td>
    <div class="choice selected">
        margin-block-start: 20px; <br>
        writing-mode: horizontal-tb;
    </div>
    
    <div class="choice">
        margin-block-start: 20px;  <br>
        writing-mode: vertical-rl;
    </div>
    
    <div class="choice">
        margin-block-start: 20%; <br>
        writing-mode: horizontal-tb;
    </div>
    
    <div class="choice">
        margin-block-start: auto; <br>
        writing-mode: vertical-lr;
    </div>
</td>
<td valign="top">
<div id="container">
            <div class="row">One</div>
            <div class="row row-target transition-all" id="example-element" style="margin-block-start: 20px; writing-mode: horizontal-tb;">Two</div>
            <div class="row">Three</div>
        </div>
        
</td></tr>
</table>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andres Separ