JSFiddle - React, Tailwind, and code Playground

HTML

<button id="button">click me</button>
<div id="background">
    <div id="box">
        <h1>Modal window</h1>
        <p>I'd expect to see a transition when adding the show class. Unfortunately, the transition is only shown when the parent's display property isn't changed at the same time.</p>
        <p id="show-later">Here the transition is applied correctly, because of a delay. To work reliably however, the delay seems to have to be over 100ms, making the UI seem sluggish.<p>
    </div>
</div>

CSS

#background{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: silver;
    
    visibility: hidden;
    opacity: 0;
}
#box{
    position: relative;
    width: 50%;
    margin-top: 30px;
    margin-left: auto;
    margin-right: auto;
    padding: 20px;
    background: white;
    border: 1px solid grey;
    
    visibility: hidden;
    opacity: 0;
}
#show-later{
    visibility: hidden;
    opacity: 0;
}
#background.show,
#box.show,
#show-later.show{
    visibility: visible;
    opacity: 1;
    transition: opacity 500ms linear;
}

JavaScript

$("#button").click( function(){
  $("#box, #background").addClass("show");
    setTimeout( function(){
      $("#show-later").addClass("show");
    }, 2000);
})