interpolate-size

`height: auto`처럼 값이 정해지지 않은 크기 속성도 트랜지션 대상에 넣을 수 있게 하는 속성.

다른 이름: Animate to height: autoAuto value transitions
···
html
<div class="wrap">
  <div class="badge" id="badge"><svg viewBox="0 0 10 10"><path id="bpath" d="M1.5 5.2l2.6 2.6L8.5 2.4" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg><span id="btext">확인 중</span></div>
  <button class="panel" id="panel">
    <div class="inner">첫 줄<br>둘째 줄<br>셋째 줄 — height:auto 로 트랜지션</div>
  </button>
</div>
css
:root{interpolate-size:allow-keywords}
.wrap{position:relative;width:min(240px,92%);display:grid;place-items:center}
.panel{width:100%;height:0;overflow:hidden;border:1px solid var(--line);border-radius:10px;background:var(--surface);
  transition:height .5s ease;padding:0;text-align:left}
.panel.open{height:auto}
.panel.fallback{transition:max-height .5s ease;max-height:0}
.panel.fallback.open{max-height:100px}
.inner{padding:12px 14px;font-size:11px;line-height:1.6;color:var(--fg)}
.badge{position:absolute;top:-30px;right:0;display:flex;align-items:center;gap:5px;padding:4px 9px;border-radius:999px;font-size:10px;font-weight:700;background:var(--bg);border:1px solid var(--line);color:var(--accent-3)}
.badge.no{color:var(--accent-2)}
.badge svg{width:9px;height:9px}
js
const ok = CSS.supports('interpolate-size', 'allow-keywords');
const b=document.getElementById('badge'),p=document.getElementById('bpath'),t=document.getElementById('btext');
b.classList.toggle('no', !ok);
p.setAttribute('d', ok ? 'M1.5 5.2l2.6 2.6L8.5 2.4' : 'M2 2l6 6M8 2l-6 6');
t.textContent = ok ? 'interpolate-size 지원됨' : '미지원 · max-height 폴백';
const panel = document.getElementById('panel');
if (!ok) panel.classList.add('fallback');
panel.classList.add('open');
setInterval(() => panel.classList.toggle('open'), 2200);

`height: 0`에서 `height: auto`로 트랜지션하는 건 CSS의 오래된 한계였습니다. 브라우저는 `auto`가 최종적으로 몇 px일지 렌더 전에는 모르기 때문에, 그 사이를 보간할 수 없었습니다. 그래서 아코디언 펼침 애니메이션은 `max-height`를 큰 값으로 잡는 눈속임이나 `grid-template-rows: 0fr↔1fr` 트릭, 혹은 JS로 `scrollHeight`를 재는 방법에 의존해 왔습니다.

`interpolate-size: allow-keywords`를 `:root`에 선언하면 브라우저가 `auto` 같은 키워드 값도 트랜지션 가능한 크기로 취급합니다. 그러면 `height: 0 → height: auto`에 `transition: height .3s`를 그냥 붙일 수 있습니다 — 실제 콘텐츠 높이가 얼마든 상관없이.

기본 지원은 caniuse/MDN baseline을 확인하세요. 미지원 브라우저에서는 `grid-template-rows: 0fr`↔`1fr` 트릭(아코디언 항목 참고)이나 JS로 `scrollHeight`를 측정하는 방법이 여전히 표준 대안입니다.

언제 쓰나

아코디언·펼침 패널을 grid 트릭이나 JS 측정 없이, 진짜 height 트랜지션으로 만들고 싶을 때.