Transitions an element's height

Hi There, i'm Said Mounaim A passionate Intermediate Full Stack Developer having an experience of building responsive Web applications with JavaScript / React.js / Next.js / Node.js and some other cool libraries and frameworks.
Hello Guuys!
To transitions an element's height from 0 to auto when its height is unknown.
Use
transitionto specify that changes tomax-heightshould be transitioned over.Use
overflow: hiddento prevent the contents of the hidden element from overflowing its container.Use
max-heightto specify an initial height of0.Use the
:hoverpseudo-class to change themax-heightto the value of the--max-heightvariable set by JavaScript.Use
Element.scrollHeightandCSSStyleDeclaration.setProperty()to set the value of--max-heightto the current height of the element.
<div class="trigger">
Hover me
<div class="el">Additional content</div>
</div>
.el {
transition: max-height 0.3s;
overflow: hidden;
max-height: 0;
}
.trigger:hover > .el {
max-height: var(--max-height);
}
let el = document.querySelector('.el');
let height = el.scrollHeight;
el.style.setProperty('--max-height', height + 'px');
If you find It useful don't forget to Like and Follow for more.



