CSS field-sizing Property

The field-sizing property controls whether certain form controls use their default sizing behavior or adjust their dimensions to fit their content.

It is particularly useful for text inputs, textareas, and select elements that need to grow as their content changes. With field-sizing: content, supported controls can adapt to their contents without requiring JavaScript to calculate their dimensions.

field-sizing Syntax

The field-sizing property accepts two keyword values: fixed and content.

Basic Syntax

selector {
  field-sizing: content;
}

Keyword Values

input {
  field-sizing: fixed;
}
input {
  field-sizing: content;
}

Multiple Form Controls

input,
textarea,
select {
  field-sizing: content;
}

CSS-Wide Keywords

input {
  field-sizing: inherit;
}
input {
  field-sizing: initial;
}
input {
  field-sizing: unset;
}
input {
  field-sizing: revert;
}
input {
  field-sizing: revert-layer;
}

The initial value is fixed, which preserves the control's normal sizing behavior.

Property Values

The field-sizing property determines how a supported form control calculates its preferred size.

Value Description
fixed Uses the form control's normal sizing behavior rather than automatically sizing to its content.
content Allows the form control's preferred size to be determined by its content, subject to layout constraints.

CSS-Wide Values

Value Description
inherit Uses the computed value of the parent element.
initial Restores the initial value, fixed.
unset Uses the initial value because the property is not inherited.
revert Reverts the property according to the CSS cascade origins.
revert-layer Reverts the property according to the CSS cascade layers.

Property Characteristics

Characteristic Value
Initial value fixed
Inherited No
Applies to Form controls with intrinsic sizing behavior
Computed value As specified
Animation type Discrete
Percentages Not applicable

The visible result depends on the type of form control, its content, and any width or height constraints applied through CSS.

How It Works

Form controls normally use predefined intrinsic sizes or dimensions supplied by HTML attributes and CSS. The field-sizing: content declaration changes how supported controls determine their preferred dimensions.

Step 1: Create a Form Field

<label for="example-name">Name:</label>
<input type="text" id="example-name" value="HTML">

Step 2: Enable Content-Based Sizing

input {
  field-sizing: content;
}

Step 3: Enter More Text

As the input's value becomes longer, the browser can increase its preferred width to accommodate the text.

Step 4: Add Size Constraints

input {
  field-sizing: content;
  min-width: 100px;
  max-width: 100%;
}

The minimum width prevents the input from becoming excessively narrow, while the maximum width helps keep it inside its container.

Important Distinction

The property does not automatically override an explicitly assigned width or height. Content-based sizing operates within the normal CSS sizing and layout rules.

fixed

The fixed value preserves the form control's normal sizing behavior.

Basic Example

input {
  field-sizing: fixed;
}

HTML Example

<label for="fixed-name">Name:</label>
<input type="text" id="fixed-name" value="HTML">

How It Works

The input uses its usual preferred width. Entering additional characters does not automatically expand the field to fit its contents.

Explicit Width

input {
  field-sizing: fixed;
  width: 250px;
}

The control remains 250 pixels wide unless other layout rules override that width.

Practical Uses

Use fixed when consistent field dimensions are important, such as in structured forms with aligned labels and controls.

Important Consideration

The name fixed does not mean the control must have a fixed pixel width. It means that content-based intrinsic sizing is disabled.

content

The content value allows supported form controls to calculate their preferred size from their contents.

Basic Example

input {
  field-sizing: content;
}

HTML Example

<label for="content-name">Name:</label>
<input type="text" id="content-name" value="HTML and CSS">

How It Works

The input's preferred width is based on the space required by its current content. As the value changes, the browser may recalculate that width.

Minimum Width

input {
  field-sizing: content;
  min-width: 120px;
}

Maximum Width

input {
  field-sizing: content;
  max-width: 300px;
}

Practical Uses

Content-based sizing is useful for short editable labels, compact search fields, automatically expanding textareas, and other controls whose dimensions should reflect their contents.

Important Consideration

Without appropriate minimum and maximum sizes, a field may become very small when empty or excessively large when its content grows.

Text Inputs

Single-line text inputs are among the most common uses of field-sizing: content.

Basic Text Input

<label for="username">Username:</label>
<input type="text" id="username" value="WebDesigner">
input[type="text"] {
  field-sizing: content;
  min-width: 100px;
  max-width: 100%;
}

Search Input

<label for="site-search">Search:</label>
<input type="search" id="site-search" placeholder="Search tutorials">
input[type="search"] {
  field-sizing: content;
  min-width: 180px;
  max-width: 100%;
}

Email Input

<label for="email-address">Email:</label>
<input type="email" id="email-address" value="hello@example.com">
input[type="email"] {
  field-sizing: content;
  min-width: 200px;
  max-width: 100%;
}

Password Inputs

Password inputs can also use content-based sizing, but their dimensions may change as masked characters are entered. A stable width is often preferable for password fields.

Important Consideration

Not all input types behave like ordinary text fields. Buttons, checkboxes, radio buttons, and specialized input controls may have different intrinsic sizing behavior.

Textareas

The field-sizing property is particularly useful for textareas because it allows their preferred dimensions to respond to the amount of entered text.

Basic Example

<label for="comments">Comments:</label>
<textarea id="comments" placeholder="Enter your comments"></textarea>
textarea {
  field-sizing: content;
}

Automatic Vertical Growth

textarea {
  field-sizing: content;
  width: 100%;
  min-height: 100px;
  max-height: 300px;
  box-sizing: border-box;
}

The textarea can grow vertically as additional lines are entered, up to its maximum height.

Limit Horizontal Growth

textarea {
  field-sizing: content;
  min-width: 200px;
  max-width: 100%;
}

Control Overflow

textarea {
  field-sizing: content;
  width: 100%;
  max-height: 250px;
  overflow-y: auto;
}

When the content exceeds the maximum height, the textarea can scroll rather than continuing to expand.

Important Consideration

Content-based sizing does not replace all textarea layout controls. Use min-height, max-height, and overflow to maintain a usable editing area.

Select Elements

The field-sizing property can influence the preferred dimensions of select controls.

Basic Example

<label for="topic">Topic:</label>
<select id="topic">
  <option>HTML</option>
  <option>CSS Properties</option>
  <option>JavaScript Tutorials</option>
</select>
select {
  field-sizing: content;
}

How It Works

With field-sizing: content, a single-select control can size itself according to the currently selected option rather than reserving space for its longest option.

Constrain the Width

select {
  field-sizing: content;
  min-width: 120px;
  max-width: 100%;
}

Multiple Select Controls

<label for="skills">Skills:</label>
<select id="skills" multiple>
  <option>HTML</option>
  <option>CSS</option>
  <option>JavaScript</option>
</select>

Multiple-selection controls have different content and layout requirements. Their preferred dimensions can depend on the options and control type.

Important Consideration

Changing the selected option can cause a single-select control to change width. Use a minimum width when a stable layout is important.

Placeholder Text

Placeholder text can influence the preferred size of content-sized form controls when no entered value is present.

Basic Example

<input type="text" placeholder="Enter your name">
input {
  field-sizing: content;
}

How It Works

The placeholder can contribute to the input's content-based width. Once the user enters text, the field can adjust to the entered value.

Minimum Width

input {
  field-sizing: content;
  min-width: 150px;
}

Textarea Placeholders

<textarea placeholder="Describe your project"></textarea>

A textarea's placeholder can also influence its initial preferred dimensions.

Accessibility Consideration

Placeholder text is not a replacement for a visible label. Always provide an appropriate label for form controls.

Minimum and Maximum Sizes

Content-based sizing works best when combined with minimum and maximum size constraints.

Minimum Width

input {
  field-sizing: content;
  min-width: 120px;
}

Prevents the field from becoming too narrow when its content is short or empty.

Maximum Width

input {
  field-sizing: content;
  max-width: 400px;
}

Prevents the field from expanding beyond the specified width.

Responsive Maximum Width

input {
  field-sizing: content;
  min-width: 120px;
  max-width: 100%;
}

Textarea Height Limits

textarea {
  field-sizing: content;
  width: 100%;
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  box-sizing: border-box;
}

Important Consideration

Minimum sizes should be chosen carefully for narrow screens. A large min-width can cause horizontal overflow even when max-width: 100% is specified.

field-sizing and HTML Attributes

Several HTML attributes traditionally influence the dimensions of form controls. The field-sizing property changes how supported controls use those intrinsic sizing rules.

The size Attribute

<input type="text" size="30">

The size attribute normally influences the preferred width of a text input.

input {
  field-sizing: content;
}

With content-based sizing, the input's preferred width is based on its content instead of the usual width derived from the size attribute.

The cols Attribute

<textarea cols="40"></textarea>

The cols attribute normally influences the preferred width of a textarea. Content-based sizing changes that intrinsic sizing behavior.

The rows Attribute

<textarea rows="5"></textarea>

The rows attribute normally influences the preferred height of a textarea. Content-based sizing allows the textarea to determine its preferred dimensions from its content instead.

The maxlength Attribute

<input type="text" maxlength="20">

The maxlength attribute limits the number of characters that can be entered. It does not directly establish the rendered width of the field.

Important Consideration

HTML attributes continue to serve their semantic and behavioral purposes. Use CSS width and height constraints when precise visual dimensions are required.

field-sizing vs. resize

The field-sizing and resize properties both affect form control dimensions, but they serve different purposes.

field-sizing

textarea {
  field-sizing: content;
}

Allows the browser to calculate the control's preferred dimensions based on its content.

resize

textarea {
  resize: vertical;
}

Controls whether and in which directions the user can manually resize an eligible element.

Combined Example

textarea {
  field-sizing: content;
  resize: vertical;
  min-height: 100px;
  max-height: 300px;
}

Comparison

Behavior field-sizing resize
Content-based sizing Yes, with content No
Manual user resizing Does not control it Controls permitted directions
Initial value fixed none
Inherited No No

Recommended Approach

Use field-sizing: content when the control should respond to its content. Use resize when the user should be able to adjust the control's dimensions manually.

field-sizing Example

This example compares a conventional text input with a content-sized input and demonstrates an automatically expanding textarea.

HTML Example

<div class="field-sizing-demo">
  <label for="fixed-field">Fixed Sizing:</label>
  <input type="text" id="fixed-field" value="HTML" class="fixed-field">
  <label for="content-field">Content Sizing:</label>
  <input type="text" id="content-field" value="HTML" class="content-field">
  <label for="growing-message">Growing Textarea:</label>
  <textarea id="growing-message" class="growing-message" placeholder="Enter multiple lines of text"></textarea>
</div>

CSS Example

.field-sizing-demo {
  display: grid;
  gap: 10px;
  max-width: 450px;
}
.field-sizing-demo label {
  font-weight: bold;
}
.field-sizing-demo input,
.field-sizing-demo textarea {
  border: 1px solid #999999;
  padding: 8px;
  font: inherit;
  box-sizing: border-box;
}
.field-sizing-demo .fixed-field {
  field-sizing: fixed;
  width: 250px;
  max-width: 100%;
}
.field-sizing-demo .content-field {
  field-sizing: content;
  min-width: 100px;
  max-width: 100%;
}
.field-sizing-demo .growing-message {
  field-sizing: content;
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
}
Browser Result

Try entering additional text into both inputs. The fixed-width input retains its assigned width, while the content-sized input can expand as its text becomes longer.

Next, enter several lines into the textarea. In supporting browsers, its height increases as more content is entered, up to the specified maximum height.

Browsers without support for field-sizing: content display the controls using their normal sizing behavior.

Accessibility

Content-sized form controls should remain easy to identify, navigate, and use as their dimensions change.

Provide Visible Labels

Use the HTML <label> element to identify form fields. Placeholder text alone is not a sufficient replacement.

Maintain Usable Minimum Sizes

Set appropriate minimum dimensions so empty fields remain easy to recognize and interact with.

Prevent Layout Shifts

Expanding controls can move nearby content. Avoid unexpected movement that makes forms difficult to complete.

Support Keyboard Navigation

Ensure that controls remain keyboard accessible and retain visible focus indicators.

Allow Text Enlargement

Use responsive dimensions and avoid unnecessarily restrictive maximum heights that make enlarged text difficult to read or edit.

Preserve Textarea Usability

When limiting textarea height, allow scrolling so visitors can review and edit content that exceeds the visible area.

Browser Fallbacks

Forms should remain fully functional when the property is unsupported. Content-based sizing should enhance the interface rather than be required for basic operation.

Important Considerations

Keep the following points in mind when using field-sizing:

  • Purpose: Controls whether supported form controls use normal or content-based intrinsic sizing.
  • Initial value: fixed.
  • Inheritance: The property is not inherited.
  • fixed: Preserves normal form control sizing behavior.
  • content: Allows the preferred size to respond to the control's contents.
  • Text inputs: Can expand horizontally as text is entered.
  • Textareas: Can grow as additional lines are entered.
  • Select controls: Can adjust their preferred dimensions according to their content.
  • Placeholder text: Can contribute to the preferred dimensions of empty controls.
  • Minimum sizes: Prevent controls from becoming too small.
  • Maximum sizes: Prevent excessive expansion.
  • Explicit dimensions: Assigned widths and heights continue to participate in normal CSS sizing.
  • HTML attributes: Content-based sizing changes how certain intrinsic sizing attributes affect preferred dimensions.
  • resize: Controls manual resizing separately from content-based sizing.
  • Animation: Changes between property values are discrete.
  • Accessibility: Growing fields should not cause confusing layout shifts or become difficult to use.
  • Browser support: The property has limited availability and requires fallback-friendly designs.

For most content-sized fields, combine field-sizing: content with suitable minimum and maximum dimensions. This provides flexibility while maintaining a predictable layout.

Browser Support

The CSS field-sizing property has Limited availability. Support is not yet consistent across all major browsers, so it is not considered a Baseline feature.

Chromium-based browsers support field-sizing: content, while support in other browser engines may differ. Check current compatibility before relying on it in production.

Basic Feature Detection

@supports (field-sizing: content) {
  textarea {
    field-sizing: content;
  }
}

Fallback Example

textarea {
  width: 100%;
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  box-sizing: border-box;
}
@supports (field-sizing: content) {
  textarea {
    field-sizing: content;
  }
}

Compatibility Considerations

When unsupported, browsers ignore the field-sizing declaration and retain their usual form control sizing behavior.

Feature detection confirms whether the browser recognizes the property and value, but the visual result still depends on the form control type and its CSS layout constraints.

For current compatibility information, visit Can I Use? .

Specifications

The field-sizing property is defined in CSS Basic User Interface Module Level 4.

CSS Basic User Interface Module Level 4: field-sizing

The specification describes the fixed and content values, intrinsic sizing behavior, and how supported form controls determine their preferred dimensions.

Because the feature is still developing, browser implementations and compatibility may change as the specification evolves.