What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put a textarea and a hidden copy of its text in the same CSS Grid cell. As the copy grows to fit the text, the grid grows too—and the textarea grows with it. A small input listener keeps the copy in sync.

Build an autogrowing textarea with CSS Grid

This pattern, published by Chris Coyier on CSS-Tricks on November 11, 2020, uses a hidden content replica to determine the textarea’s height. The textarea remains the visible, interactive control; the replica supplies the height needed to fit its text.

HTML

<div class="grow-wrap" data-replicated-value="">
  <textarea aria-label="Comment"></textarea>
</div>

CSS

.grow-wrap {
  display: grid;
}

.grow-wrap::after {
  content: attr(data-replicated-value) " ";
  white-space: pre-wrap;
  visibility: hidden;
}

.grow-wrap > textarea,
.grow-wrap::after {
  grid-area: 1 / 1 / 2 / 2;
  border: 1px solid #888;
  padding: .5rem;
  font: inherit;
  margin: 0;
}

.grow-wrap > textarea {
  resize: none;
  overflow: hidden;
}

JavaScript

const wrapper = document.querySelector('.grow-wrap');
const textarea = wrapper.querySelector('textarea');

const sync = () => {
  wrapper.dataset.replicatedValue = textarea.value;
};

textarea.addEventListener('input', sync);
sync();

The final sync() call handles text already in the textarea when the page loads. Without it, the hidden replica starts empty and the wrapper may not be tall enough for preloaded content.

Why the replica makes the textarea grow

The wrapper uses display: grid, and both the textarea and its ::after pseudo-element occupy the same cell. The pseudo-element’s content comes from the wrapper’s data-replicated-value attribute. As that text wraps onto additional lines, the pseudo-element’s natural height increases; the shared grid row takes the height of its tallest child, and the textarea fills that space.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Logitech Ergo K860 Wireless Ergonomic Split Keyboard with Wrist Rest
  • Improved Typing Posture: Type more naturally with a curved, split keyframe and reduce muscle strain on your wrists and forearms thanks to the sloping keyboard design
  • Pillowed Wrist Rest: Curved wrist rest with memory foam layer offers typing comfort with 54 per cent more wrist support; 25 per cent less wrist bending compared to standard keyboard without palm rest
  • Perfect Stroke Keys: Scooped keys match the shape of your fingertips so you can type with confidence on a wireless keyboard crafted for comfort, precision and fluidity
  • Adjustable Palm Lift: Whether seated or standing, keep your wrists in total comfort and a natural typing posture with ergonomically-designed tilt legs of 0, -4 and -7 degrees
  • Ergonomist Approved: The ERGO K860 wireless ergonomic keyboard is certified by United States Ergonomics to improve posture and lower muscle strain

On each input event, the listener copies the textarea’s current value into the data attribute. The browser then recalculates the pseudo-element’s content and grid layout. This is the only JavaScript the pattern needs. Coyier describes the core idea as replicating the textarea’s content in an element that can expand naturally and matching its sizing: CSS-Tricks: The Cleanest Trick for Autogrowing Textareas.

Match the replica’s text and box sizing

The replica must wrap and measure text like the textarea. Use white-space: pre-wrap so line breaks and wrapping behave like multiline input. Keep the relevant styles aligned, including font, width, padding, border, and margin. A small mismatch can make the replica wrap at a different point or produce a different height, so the textarea may appear to jump or stop matching the text. The CSS-Tricks walkthrough discusses the importance of matching these styles: CSS-Tricks sizing notes.

Rank #2
Sale
Logitech Wave Keys Ergonomic Wireless Keyboard with Palm Rest - Graphite
  • Feel the Wave: Get comfier with Wave Keys, the ergonomic wireless keyboard shaped to help workdays go easier on you
  • Type in comfort all day long: The wavy design of this compact keyboard places your hands, wrists and forearms in a natural typing position
  • More palm support, less pressure: A cushioned palm rest with memory foam supports you all day long and gives you more wrist support (1)
  • Smoother days, your way: Personalize your Wave Keys experience using the Logi Options+ App, where you can choose shortcuts that save time and keep your work flowing (2)
  • Ergo-certified: The Wave Keys Ergonomic Keyboard has been designed and tested according to criteria set out by leading ergonomists and is approved by United States Ergonomics

The literal space after attr(data-replicated-value) is deliberate. Keep content: attr(data-replicated-value) " "; rather than removing the trailing string; Coyier notes that the extra space avoids jumpy sizing near the end of the content. See the CSS-Tricks explanation of the trailing space.

Control manual resizing and scrollbars

resize: none disables the browser’s manual resize handle, preventing a user-set height from competing with the automatic one. overflow: hidden suppresses the textarea’s scrollbar as it grows. Those choices suit a textarea intended to expand with its content; if users need a manual resize handle or a scrolling field, adjust the CSS to suit that interaction instead.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Arteck Split Ergonomic Keyboard with Palm Rest, 2.4G USB Wireless Keyboard
  • Split Design Ergonomic: Split design helps to position wrists and forearms in a natural, relaxed position. Arteck Split Ergonomic Keyboard with Cushioned Wrist and Palm Rest, 2.4G USB Wireless Comfortable Natural Ergonomic Split Keyboard, for Windows Computer Desktop Laptop
  • Wrist Rest: Soft cushioned wrist rest helps you to rest your wrist and forearm while typing and makes work easier and more comfortable.
  • Easy Setup: Simply insert the nano USB receiver (stored at the back of the keyboard) into your computer and use the keyboard instantly.
  • 6-Month Battery Life: Rechargeable lithium battery with an industry-high capacity lasts for 6 months with single charge (based on 2 hours non-stop use per day).
  • Package contents: Arteck Split Ergonomic Keyboard, nano USB receiver (stored at the back of the keyboard), USB-C charging cable, welcome guide, our 24-month warranty and friendly customer service.

When to use a scrollHeight-based alternative

A conventional JavaScript approach measures scrollHeight on every input, usually after resetting the textarea’s height so it can shrink when text is deleted. It is direct, but the code must account for padding, overflow, and any maximum height. The Grid-replica pattern delegates the height calculation to layout, while a scrollHeight implementation may be easier to adapt when the desired behavior is explicitly controlled by JavaScript.

Choose between them based on how you need the field to behave: how much code and styling you want to maintain, whether long wrapped lines must fit, whether content is preloaded, whether the field should stop at a maximum height and scroll, and how you want to structure the hidden content. The Grid pattern handles preloaded content when you call the sync function during setup. The CSS-Tricks article presents it as a clean approach while acknowledging JavaScript-based alternatives: CSS-Tricks.

Rank #4
Sale
Wireless Keyboard and Mouse Combo, 2.4G Ergonomic Wave Keys(Black)
  • 【Wave Ergonomic Wireless Keyboard and Mouse Combo】The wireless keyboard features a wave key and wrist rest design that naturally fits your fingers and relieves wrist strain. The adjustable stand allows you to set the keyboard to the most comfortable height, making it ideal for long-term use. Note: The USB receiver is located on the back of the mouse.
  • 【Wireless Optical Mouse】The wireless mouse is designed with comfort in mind, featuring a contoured shape that fits snugly in the palm and complements the natural curve of your right hand. All controls are easily within reach. This mouse is equipped with forward and back functions, allowing you to navigate the web faster and more efficiently than ever before.
  • 【Plug-and-Play 2.4G Wireless Connection】One 2.4 GHz USB receiver can connect both the keyboard and mouse, or they can be used separately. Plug and play—no software download is required. The 2.4 GHz wireless connection offers a strong and reliable signal up to 33 feet (10 meters), without delays.
  • 【Automatic Power Saving Function】The ULSOU wireless keyboard and mouse combo features an automatic power-saving function. After 30 seconds of inactivity on the keyboard and 15 minutes of inactivity on the mouse, both devices enter sleep mode to conserve battery life. This greatly extends battery life, and any button press will activate the devices again. The keyboard requires 1 AA battery, and the mouse requires 1 AA battery. (batteries not included).
  • 【Wide Compatibility and Dual System Layout】This wireless keyboard and mouse combo is compatible with Windows XP/Vista/7/8/10/11, Mac, and other operating systems. It’s suitable for desktops, Chromebooks, PCs, laptops, and more. You can switch between Windows and macOS by pressing FN+Q or FN+W.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Accessibility and the hidden replica

The textarea remains the actual control users interact with and the field whose value is submitted. In this implementation, the replica is a pseudo-element rather than a separate focusable form control. Coyier raises the possibility of using a real replica element with aria-hidden="true", but the article does not establish that choice as a tested standard. If you change the structure, make sure the replica does not become an extra interactive or announced control.

Quick Recap

Bestseller No. 5
Kensington Pro Fit Ergonomic Wired Keyboard- Black (K75400US)
Kensington Pro Fit Ergonomic Wired Keyboard- Black (K75400US)
Built-in wrist rest supports, cushions, and cradles the wrists.; Quiet keys mean typing is smooth, easy, and non-disruptive.
$39.99
Best Value
Kensington Pro Fit Ergonomic Wired Keyboard- Black (K75400US)
  • Built-in wrist rest and neutral grip supports, cushions, and positions the wrist for comfort and neutral hand alignment.
  • Built-in wrist rest supports, cushions, and cradles the wrists.
  • Quiet keys mean typing is smooth, easy, and non-disruptive.
  • Spill-proof keys make cleanup fast and easy; Meets MIL-STD-810H Method 504.3 Contamination by Fluids testing for resistance to breakdown when exposed to cleaning and disinfecting solvents such as alcohol and bleach for at least 24 hours
  • Caps lock, numbers lock, scroll lock, and F-keys are popular features that make typing and navigating easier and more efficient.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.