--- url: "https://www.w3.org/WAI/WCAG22/Techniques/css/C38" titulek: "C38: Using CSS width, max-width and flexbox to fit labels and inputs | WAI | W3C" h1: "Technique C38:Using CSS width, max-width and flexbox to fit labels and inputs" popis: "" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 05:31:50" znaku: 4782 slov: 757 kodovani: "utf-8" sha256: "71c8794c8c5899486222ee6e2f2ac79f587f2903b4eed6d0ae80a3f5c14c3c08" --- # Technique C38:Using CSS width, `max-width` and flexbox to fit labels and inputs ## About this Technique This technique relates to [1.4.10 Reflow](https://www.w3.org/WAI/WCAG22/Understanding/reflow) (**Sufficient**). This technique applies to CSS and HTML. Techniques are examples of ways to meet Web Content Accessibility Guidelines (WCAG). They are **not required** to meet WCAG. Content can satisfy the normative requirements of WCAG even if it does not use any of the documented techniques. See [About WCAG Techniques](https://www.w3.org/WAI/WCAG22/Techniques/about). ## Description The objective of this technique is to be able to present labels and inputs without introducing a horizontal scroll bar at a width equivalent to 320 CSS pixels for content intended to scroll vertically. When space is limited in the viewport for the label and input to sit next to each other horizontally, they will be changed to a vertical alignment. This is done by using CSS properties for `width`, `max-width` and flexbox that adapt to the available space. Responsive layouts can add or remove columns or layout blocks, and each part of the layout can be wider or smaller at different points. This technique ensures labels and inputs do not break out of their layout area, including in one-column layouts where it would cause horizontal scrolling. The basic approach for fitting labels and inputs is to: 1. Define the size of layout regions using flexbox properties and media queries for specific viewport sizes, so they enlarge, shrink or wrap in the available space and respond to zoom levels; 2. Position the layout regions in the flexbox container as a row of adjacent flexbox items, which may wrap to new rows as needed in much the same way as words in a paragraph wrap. 3. Define the width and max-width property for labels and inputs so they enlarge or shrink in the available space and respond to zoom levels. All labels and inputs require design finesse by making sure the original size fits the biggest size of the available spaces to achieve good-looking results at a wide range of viewport sizes and zoom levels. For help on flexbox please see the [MDN article on Flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox). ## Examples ### Example 1: Fitting labels, inputs and flexbox layout with HTML and CSS. The following example uses HTML and CSS to fit labels and inputs within various width containers, including the viewport. The layout regions adjust their size as the viewport is adjusted. The labels and inputs subsequently adjust their size to fit within the layout region containers. The zoom level can be increased to 400% without requiring horizontal scrolling. This particular example uses a percent size for the `width` and `max-width` for the labels and inputs. The `max-width` is applied in order to fix elements spilling out of the grid in a cross-browser way, as replaced elements such as the `select` have intrinsic sizing. ```
``` Working example: [Using Adjustable Labels and Inputs for Reflow](../../working-examples/css-fit-labels-inputs/) ## Tests ### Procedure 1. Display the web page in a user agent capable of 400% zoom and set the viewport dimensions (in CSS pixels) to 1280 wide and 1024 high. 2. Zoom in by 400%. 3. For vertically scrolling content, all labels and inputs fit in their available space without horizontal scrolling. NB: If the browser is not capable of zooming to 400%, you can reduce the width of the browser proportionally. For example, at 300% zoom the viewport should be sized to 960px wide. ### Expected Results Check #3 is true. Back to Top