CSS field-sizing

The CSS field-sizing property controls whether a form control keeps a conventional fixed size or adapts to its content. With field-sizing: content, you can create inputs and text areas that expand as a user types, often without JavaScript.

This property became broadly available in modern browsers during 2026. It works best as a progressive enhancement: set sensible minimum and maximum dimensions so the form remains usable even when content grows.

CSS field-sizing Values

Value Behavior
fixed Uses the control’s normal fixed-size behavior. This is the initial value.
content Lets the control adjust its size from its displayed content.

Create a Content-Sized Input

Apply field-sizing: content to the input, then add an inline minimum and maximum. The constraints prevent a short value from creating a tiny field and a long value from breaking the page layout.

Example:

input {
  /* Let the field grow with its current text. */
  field-sizing: content;
  min-inline-size: 12rem;
  max-inline-size: 100%;
}

The placeholder can influence the field’s initial content size. Keep placeholder text concise and use a visible label to describe the field. A placeholder should not replace an accessible label.

Create an Auto-Growing Text Area

A text area can grow vertically as the user adds lines. Use logical block-size properties to set useful limits. When the maximum is reached, overflow: auto allows the remaining content to scroll.

Example:

<label for="notes">Delivery notes</label>
<textarea id="notes" placeholder="Add gate or floor details"></textarea>
textarea {
  /* Grow with the entered lines, within safe limits. */
  field-sizing: content;
  min-block-size: 4rem;
  max-block-size: 14rem;
  inline-size: 100%;
  overflow: auto;
}

Combine Width and Height Constraints

Content sizing does not remove normal CSS sizing rules. You can combine it with min-inline-size, max-inline-size, min-block-size, and max-block-size. These logical properties also adapt to vertical writing modes.

Example:

.search-field {
  /* Keep the field comfortable on small and large screens. */
  field-sizing: content;
  min-inline-size: 16ch;
  max-inline-size: min(34rem, 100%);
}

Build a Flexible Form

The next example uses content sizing for both a single-line subject field and a multi-line message. Edit the values in the online editor to see how each control responds.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS field-sizing Demo</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 2rem; color: #253545; }
    form { max-width: 620px; padding: 1.25rem; border: 1px solid #ccd5df; border-radius: 8px; }
    label { display: block; margin-top: 1rem; font-weight: 700; }
    input, textarea { field-sizing: content; min-inline-size: 14rem; max-inline-size: 100%; padding: .65rem; margin-top: .4rem; border: 1px solid #7b8794; border-radius: 4px; font: inherit; }
    textarea { min-block-size: 4rem; max-block-size: 12rem; overflow: auto; }
  </style>
</head>
<body>
  <h1>Flexible Feedback Form</h1>
  <form>
    <label for="subject">Subject</label>
    <input id="subject" placeholder="Type a subject">
    <label for="message">Message</label>
    <textarea id="message" placeholder="Add more detail and watch this field grow"></textarea>
  </form>
</body>
</html>

Provide a Safe Fallback

Browsers that do not understand field-sizing ignore it and keep the default fixed behavior. Define ordinary dimensions first, then add the enhancement. This keeps the form readable in older browsers.

Example:

.message {
  /* Fallback dimensions work everywhere. */
  width: 100%;
  min-height: 8rem;

  /* Supporting browsers can size from the content. */
  field-sizing: content;
  max-block-size: 16rem;
}

If the exact behavior changes an important workflow, you can test support in CSS.

Example:

@supports (field-sizing: content) {
  .compact-field {
    /* Apply enhancement only when supported. */
    field-sizing: content;
  }
}

Design and Accessibility Guidelines

  • Always connect each control to a visible label.
  • Set minimum dimensions so empty controls remain easy to find and operate.
  • Set maximum dimensions to prevent long content from shifting nearby controls.
  • Test keyboard input, browser zoom, long unbroken text, and narrow screens.
  • Keep overflow available when a text area reaches its maximum height.

Tip: Use content sizing where expansion helps users review their entry. A fixed size may still be better when a stable layout is more important.

Conclusion

CSS field-sizing can make form controls respond naturally to their content with very little code. Use content for adaptive sizing, keep firm minimum and maximum limits, and retain ordinary dimensions as a fallback. These checks produce flexible forms without sacrificing layout stability or accessibility.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram