Back to CSS Input Fields Auto-Grow Textarea Pure CSS
Share
HTML
<label class="if-grow">
  <span class="if-grow-label">Notes</span>
  <textarea name="notes" rows="2" placeholder="Type as much as you need..."></textarea>
  <span class="if-grow-hint">Field grows as you type</span>
</label>
CSS
.if-grow {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 320px;
}

.if-grow-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #b8b6d4;
  text-transform: uppercase;
}

.if-grow textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  background: #1a1a22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: #f0eeff;
  font:
    500 14px/1.55 system-ui,
    sans-serif;
  outline: none;
  resize: none;
  min-height: 64px;
  field-sizing: content;
  transition:
    border-color 0.2s,
    background 0.2s;
}

.if-grow textarea:focus {
  border-color: #a78bfa;
  background: #1f1f2a;
}

.if-grow textarea::placeholder {
  color: #b8b6d4;
}

.if-grow-hint {
  font-size: 11px;
  color: #b8b6d4;
}