Autoresize (Pure CSS)

Mode

Skin

Theme

Sidebar

Overview & Philosophy

data-ln-autoresize is applied directly to multi-line input fields via <textarea data-ln-autoresize rows="1">. In ln-ashlar, this is a 100% Pure CSS UX utility powered natively by the browser's field-sizing: content property.

By leveraging the platform's native rendering engine, textareas expand and contract dynamically during typing, pasting, content deletions, and programmatic value updates with zero JavaScript, zero event listeners, and zero layout thrashing.

Zero-JS Native Performance: field-sizing: content

Legacy JavaScript autoresize techniques reset height = 'auto' and synchronously read scrollHeight on every single keystroke, causing severe forced synchronous reflows (Layout Thrashing). With field-sizing: content, the browser's C++ rendering pipeline calculates dimensions intrinsically during normal layout passes, maintaining 60fps responsiveness under high typing frequencies.

Concerns Scoped Strictly by Layer

The growing input experience is achieved by decoupling layout ceilings, browser defaults, and active styling:

  1. The Content Shell (HTML rows Attribute): Standard inputs default to rows="2". Explicitly declaring rows="1" sets the intrinsic single-line baseline for an empty input.
  2. The Ceiling Controller (CSS Constraints): Limits on maximum height are defined using standard max-height: 6rem and overflow-y: auto. This caps expansion and reveals scrollbars natively.
  3. The Visual Utility (data-ln-autoresize): Packaged in Ashlar's form stylesheets (_form.scss), automatically resetting min-height, applying field-sizing: content, and removing conflicting drag handles (resize: none).

Anatomy

The complete invocation. There is no JavaScript initialization required:

<textarea data-ln-autoresize rows="1" placeholder="Notes..."></textarea>

Built-in Ashlar CSS Rule

The core theme automatically provides the necessary intrinsic layout rules:

textarea[data-ln-autoresize] {
    field-sizing: content;
    min-height: unset;
    resize: none;
}

Pairing with CSS for capped growth

By default, intrinsic sizing grows with content indefinitely. Cap growth with a standard stylesheet rule:

#my-container textarea[data-ln-autoresize] {
    max-height: 6rem;
    overflow-y: auto;
}

Attributes reference

data-ln-autoresize operates purely on markup and stylesheet selection without synthetic attributes or coordinator glue:

AttributeOn elementLayerDescription
data-ln-autoresize<textarea>CSS / ThemeApplies native field-sizing: content, removes drag handles, and clears min-height.
rows<textarea>HTML / BrowserInitial visible row baseline when empty. Use "1" for compact inputs.

Example — Basic auto-grow

Type into the field. The box height expands and collapses smoothly with every line break without any inline style manipulation or JavaScript listeners.

Example — Pre-filled content

Server-rendered content sizes to fit on first paint. Because size calculation is intrinsic to CSS layout, there is zero initial layout flash or JavaScript execution delay.

Example — Capped at 6rem with scroll

Pair data-ln-autoresize with CSS max-height and overflow-y: auto to cap growth and enable scrolling when content exceeds the ceiling limit.

Example — Programmatic value updates

Setting el.value = … via JavaScript updates the native field size instantly in the browser's layout engine without needing synthetic event dispatches or manual re-measure calls.

Example — Form reset collapses automatically

Type a long reply, then click Reset. The textarea clears AND snaps back to its single-row starting height natively through standard browser form handling.

Example — Dynamically inserted textareas

Click the button to create a new <textarea data-ln-autoresize> via JavaScript. Because it is purely CSS-driven, dynamic DOM insertions auto-size immediately without MutationObservers or manual JavaScript initialization.

Example — Hidden-then-revealed elements

Textareas mounted inside containers with hidden or display: none recalculate their layout intrinsically when revealed. No re-measure scripts or intersection observers are necessary.