06Auto-growing textarea
As lines are added, the box itself grows taller instead of scrolling, only switching to scroll past a set max height.
Best forReview writing box, contact and support message field
scrollHeight 기반최대 높이 제한리사이즈 불가

<main class="stage">
<div class="grow is-demo" id="wrap">
<label class="grow__label" for="review">Write a review</label>
<textarea class="grow__area" id="review" rows="1" placeholder="Tell us how this product worked for you"></textarea>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-quick; // 높이가 늘어나는 시간
$easing: $ease-out;
$color: $subject-blue; // 포커스 테두리 색
// ── 데모 무대 ──────────────────────────────────────────
@include stage($stage-yellow);
.grow {
box-sizing: border-box;
width: min(280px, 86vw);
background: $subject-cream;
border-radius: $r-card;
padding: $sp-5 $sp-5 $sp-4;
box-shadow: $shadow-raised;
&__label {
display: block;
margin: 0 0 $sp-2;
font-weight: 700;
font-size: 13px;
line-height: 1;
font-family: inherit;
color: $stage-ink;
}
&__area {
box-sizing: border-box;
display: block;
width: 100%;
min-height: 40px;
max-height: 132px;
resize: none;
overflow-y: auto;
border: 2px solid transparent;
border-radius: $r-control;
padding: $sp-3 $sp-4;
font-weight: 500;
font-size: clamp(13px, 3.8vw, 15px);
line-height: 1.4;
font-family: inherit;
color: $stage-ink;
background: #fff;
transition: height $duration $easing, border-color $duration $easing;
&:focus { outline: none; border-color: $color; }
}
}
@media (prefers-reduced-motion: reduce) {
.grow__area { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.grow {
box-sizing: border-box;
width: min(280px, 86vw);
background: #fff7e6;
border-radius: 16px;
padding: 20px 20px 16px;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.grow__label {
display: block;
margin: 0 0 8px;
font-weight: 700;
font-size: 13px;
line-height: 1;
font-family: inherit;
color: #17141a;
}
.grow__area {
box-sizing: border-box;
display: block;
width: 100%;
min-height: 40px;
max-height: 132px;
resize: none;
overflow-y: auto;
border: 2px solid transparent;
border-radius: 12px;
padding: 12px 16px;
font-weight: 500;
font-size: clamp(13px, 3.8vw, 15px);
line-height: 1.4;
font-family: inherit;
color: #17141a;
background: #fff;
transition: height 220ms ease-out, border-color 220ms ease-out;
}
.grow__area:focus {
outline: none;
border-color: #2f6df6;
}
@media (prefers-reduced-motion: reduce) {
.grow__area {
transition: none;
}
}(function () {
var wrap = document.getElementById('wrap');
var area = document.getElementById('review');
var MAX = 132;
function resize() {
area.style.height = 'auto';
area.style.height = Math.min(area.scrollHeight, MAX) + 'px';
}
area.addEventListener('input', resize);
function stopDemo() {
if (!wrap.classList.contains('is-demo')) return;
wrap.classList.remove('is-demo');
clearInterval(timer);
}
area.addEventListener('pointerdown', stopDemo);
area.addEventListener('keydown', stopDemo);
var full = 'The delivery was fast and the packaging was careful.\\nThe colors look almost exactly like the photos.\\nI will order again, thank you!';
var i = 0;
var timer = setInterval(function () {
if (i > full.length) { i = 0; area.value = ''; resize(); return; }
area.value = full.slice(0, i);
resize();
i += 2;
}, 90);
})();import { useRef, useState } from "react";
import styles from "./TextareaAutogrow.module.scss";
export type TextareaAutogrowProps = {
label?: string;
placeholder?: string;
maxHeight?: number;
};
export default function TextareaAutogrow({
label = "후기 작성",
placeholder = "이 상품을 써 본 느낌을 알려주세요",
maxHeight = 132,
}: TextareaAutogrowProps) {
const [value, setValue] = useState("");
const ref = useRef<HTMLTextAreaElement | null>(null);
const resize = () => {
const el = ref.current;
if (!el) return;
el.style.height = "auto";
el.style.height = Math.min(el.scrollHeight, maxHeight) + "px";
};
return (
<div className={styles.grow}>
<label className={styles.label}>{label}</label>
<textarea
ref={ref}
className={styles.area}
rows={1}
placeholder={placeholder}
value={value}
style={{ maxHeight }}
onChange={(e: any) => {
setValue(e.target.value);
resize();
}}
/>
</div>
);
}06 Auto-growing textarea — Measured area 36.821% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · CSS Input Design: 9 Form Widgets You Can Paste In
The post this demo lives in
CSS Input Design: 9 Form Widgets You Can Paste InCSS input design means the small form fields — phone numbers, card numbers, quantities, tags — that fill checkout and si See all demos in this post


