How to change a HTML element height transition. Sourced under a permissive license.

How to change a HTML element height transition – A HTML and CSS code snippet

<div class="trigger">
  Hover me to see a height transition.
  <div class="el">Additional content</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;'--max-height', height + 'px');

Tags: CSS, HTML, CSS, CSS code snippet, html code snippet, javascript, element height, html element, querySelector, scrollHeight

Image: Unsplash license

CC BY 4.0 added intro and tags – 30 Seconds of Code