Join form inputs with text, icon, button, and form-control addons in a single bordered control, in three sizes and a vertical layout.
Introduction
An input group joins one or more form inputs with addons — text, icons, buttons, or other controls — in a single control. The .input-group wrapper is a flex container that removes the inner corner radii of its children and overlaps their borders, so the group reads as one bordered element.
Key features
Input groups build on the shared form styles:
- Addons on either side of an input, or on both
- Corner radii and borders of adjacent elements merged by the wrapper
- One size class on the wrapper for every element in the group
- A vertical layout, with one level of nested horizontal groups
- Addon colors set through custom properties
Basic structure
Wrap a .form-input and one or more .input-addon elements in an .input-group. The order of the elements in the markup is the order in which they render. Label the input with a <label>, or with aria-label when the group has no visible label.
<div class="input-group mb-md">
<span class="input-addon">@</span>
<input type="text" class="form-input" placeholder="Username" aria-label="Username">
</div>
<div class="input-group mb-md">
<input type="text" class="form-input" placeholder="Recipient's username" aria-label="Recipient's username">
<span class="input-addon">@example.com</span>
</div>
<div class="mb-md">
<label for="basic-url" class="form-label">Website URL</label>
<div class="input-group">
<span class="input-addon">https://</span>
<input type="text" class="form-input" id="basic-url" aria-describedby="url-help">
</div>
<!-- Form helps placed outside the input group -->
<div class="form-help" id="url-help">Enter your website domain without the protocol</div>
</div>Form help placement. Place form help and validation feedback as siblings after the input group, not inside it, and link them to the input with aria-describedby.
Addon types
An addon is any element with the .input-addon class, a .button, or a form control nested in an addon.
Text addons
The .input-addon class styles a <span> or a <label> as an addon with the font, padding, and border of the inputs of the group. An addon does not wrap its text.
<div class="input-group mb-md">
<span class="input-addon">$</span>
<input type="text" class="form-input" aria-label="Amount">
<span class="input-addon">.00</span>
</div>
<div class="input-group">
<label class="input-addon" for="productDescription">Description</label>
<textarea class="form-input" id="productDescription"></textarea>
</div>An addon shares its border with the adjacent control: every element after the first is shifted by one border width, so the two borders overlap.
Icon addons
Place an icon inside an .input-addon for an icon addon. The icon takes the icon size of the form size and the text color of the addon. Use a <button> as the addon when the icon triggers an action, and give it an aria-label.
<div class="input-group mb-md">
<span class="input-addon"><svg class="icon" aria-hidden="true"><use href="#lock-solid"></use></svg></span>
<input type="password" autocomplete="current-password" class="form-input" placeholder="Password" aria-label="Password">
<button class="input-addon" type="button" aria-label="Show password">
<svg class="icon" aria-hidden="true"><use href="#eye-solid"></use></svg>
</button>
</div>
<div class="input-group">
<span class="input-addon"><svg class="icon" aria-hidden="true"><use href="#search-solid"></use></svg></span>
<input type="search" class="form-input" placeholder="Search" aria-label="Search" disabled>
</div>Button addons
Add a .button directly to an input group for an action next to the input. The button keeps its own variant styles.
<div class="input-group mb-md">
<input type="text" class="form-input" placeholder="Search term" aria-label="Search term">
<button class="button primary" type="button">Search</button>
</div>
<div class="input-group">
<button class="button outline secondary" type="button">Options</button>
<input type="text" class="form-input" aria-label="Text input with button addon">
</div>Buttons in an input group sit above the inputs in the stacking order, and a focused button or input rises above its neighbors, so the focus ring and the border of the active element are never covered.
Form controls as addons
Nest a checkbox or a radio in an .input-addon element to place it next to an input. Add .mt-0 to the .check-input to align it vertically in the addon.
<div class="input-group mb-md" role="group" aria-label="Newsletter subscription">
<div class="input-addon">
<input class="check-input mt-0" type="checkbox" value="" aria-label="Subscribe to newsletter">
</div>
<input type="email" class="form-input" placeholder="Email address" aria-label="Email for newsletter">
</div>
<div class="input-group" role="group" aria-label="Task with priority">
<div class="input-addon">
<input class="check-input mt-0" type="radio" name="priority" value="high" aria-label="High priority">
</div>
<input type="text" class="form-input" placeholder="Task description" aria-label="Task description">
</div>Layout options
An input group accepts several addons and several inputs.
Multiple addons
Place more than one addon on either side of an input. The wrapper keeps the outer corners of the first and the last element rounded and squares the corners between them.
<div class="input-group mb-md">
<span class="input-addon">Name</span>
<span class="input-addon">@</span>
<input type="text" class="form-input" aria-label="Username with multiple prefixes">
</div>
<div class="input-group">
<input type="text" class="form-input" aria-label="Currency amount">
<span class="input-addon">$</span>
<span class="input-addon">USD</span>
</div>Multiple inputs
Place several inputs in one group for related values, such as a first and a last name. Add role="group" and a group label to the wrapper, and label each input.
<div class="input-group mb-md" role="group" aria-labelledby="nameAddon">
<label class="input-addon" id="nameAddon" for="multiInputFirstName">Name</label>
<input type="text" class="form-input" id="multiInputFirstName" placeholder="First" aria-label="First name">
<input type="text" class="form-input" placeholder="Last" aria-label="Last name">
</div>
<div class="input-group" role="group" aria-label="Email address">
<input type="text" class="form-input" placeholder="Username" aria-label="Username">
<span class="input-addon">@</span>
<input type="text" class="form-input" placeholder="Domain" aria-label="Domain">
</div>Validation feedback describes one input. For a form that validates each value, use separate input groups in a grid layout, each with its own feedback after it.
Sizing
Add .sm or .lg to the .input-group to change the size of every input and addon in it. The classes extend the shared form size placeholders (%form-size-sm, %form-size-md, %form-size-lg), so a group matches a standalone .form-input of the same size.
<div class="input-group sm mb-md">
<span class="input-addon">Small</span>
<input type="text" class="form-input" aria-label="Small input group example">
</div>
<div class="input-group mb-md">
<span class="input-addon">Default</span>
<input type="text" class="form-input" aria-label="Default input group example">
</div>
<div class="input-group lg">
<span class="input-addon">Large</span>
<input type="text" class="form-input" aria-label="Large input group example">
</div>Component integration
Input groups work with the other form controls and with the menu.
With select menus
A <select> with the .form-input class takes the place of an input in a group, alone or next to another input.
<div class="input-group mb-md">
<label class="input-addon" for="inputGroupSelect01">Category</label>
<select class="form-input" id="inputGroupSelect01">
<option selected>Choose...</option>
<option value="1">Products</option>
<option value="2">Services</option>
<option value="3">Resources</option>
</select>
</div>
<div class="input-group" role="group" aria-label="Price with currency">
<select class="form-input" id="inputGroupSelect02" aria-label="Currency selection">
<option value="usd" selected>USD</option>
<option value="eur">EUR</option>
<option value="gbp">GBP</option>
</select>
<input type="text" class="form-input" aria-label="Amount">
</div>With file inputs
A file input with the .form-input class joins a label addon or a button in the same way.
<div class="input-group mb-md">
<label class="input-addon" for="inputGroupFile01">Upload</label>
<input type="file" class="form-input" id="inputGroupFile01">
</div>
<div class="input-group">
<input type="file" class="form-input" id="inputGroupFile02" aria-label="File browser">
<button class="button primary" type="button">Upload</button>
</div>With menus
Place a menu toggle button and its .menu in an input group for a list of options or actions. The wrapper leaves the .menu element out of its corner and border rules, so the toggle is treated as the first or the last element of the group.
<div class="input-group">
<button class="button outline secondary caret" type="button" data-cx-toggle="menu" aria-expanded="false">Options</button>
<ul class="menu">
<li><a class="menu-item" href="#">Action</a></li>
<li><a class="menu-item" href="#">Another action</a></li>
<li><a class="menu-item" href="#">Something else</a></li>
</ul>
<input type="text" class="form-input" aria-label="Text input with dropdown">
</div>
<div class="input-group">
<input type="text" class="form-input" aria-label="Text input with dropdown">
<button class="button outline secondary caret" type="button" data-cx-toggle="menu" aria-expanded="false">Options</button>
<ul class="menu">
<li><a class="menu-item" href="#">Action</a></li>
<li><a class="menu-item" href="#">Another action</a></li>
<li><a class="menu-item" href="#">Something else</a></li>
</ul>
</div>Vertical groups
Add .vertical to the .input-group to stack its inputs and addons. The wrapper squares the corners between the rows and overlaps their borders.
<div class="input-group vertical" role="group" aria-label="Sign-in credentials">
<input type="text" class="form-input" placeholder="Username" aria-label="Username">
<input type="password" autocomplete="current-password" class="form-input" placeholder="Password" aria-label="Password">
</div>Nested groups
Nest an .input-group in a vertical group for a row with several elements. The size class of the outer group applies to one level of nesting: set it on the outer group only.
<div class="input-group vertical" role="group" aria-labelledby="addressAddon">
<label class="input-addon" for="inputAddressLine" id="addressAddon">Address</label>
<input type="text" class="form-input" id="inputAddressLine" placeholder="123 Main St" aria-label="Street address">
<div class="input-group" role="group" aria-label="City, state, and zip">
<input type="text" class="form-input" placeholder="City" aria-label="City">
<select class="form-input" aria-label="State">
<option value="" selected>State</option>
<option>State option</option>
</select>
<input type="text" class="form-input" placeholder="Zip" aria-label="Zip code">
</div>
</div>Accessibility
Input groups combine multiple elements visually, so explicit labeling is essential for assistive technology users.
Single-input groups
Use a <label> with a for attribute pointing to the input's id. The label can be a standalone .form-label before the group, or an .input-addon element inside it. If no visible label is needed, add aria-label directly to the input.
Multi-input groups
When a group contains more than one input, add role="group" to the .input-group element so the inputs are announced as a related set. Provide a group name with either aria-labelledby referencing the id of an addon that serves as the visible group label, or aria-label when no addon is suitable. Each individual input still needs its own aria-label.
Help text and validation
Place help text and validation feedback as siblings after .input-group, not inside it. Use aria-describedby on the associated input to link the two.
Interactive addons
All button addons must have an accessible name. Use visible text, or aria-label for icon-only buttons.
CSS
The Input group component can be customized at both runtime (via custom properties) and compile time (via Sass variables).
Custom properties
The Input group component exposes CSS custom properties to control its appearance at runtime.
--input-addon-fg-color: #{$input-addon-fg-color};
--input-addon-bg-image: #{$input-addon-bg-image};
--input-addon-bg-color: #{$input-addon-bg-color};
--input-addon-border-color: #{$input-addon-border-color};The forms overview lists the custom properties shared by all form elements.
Sass variables
The Input group component uses Sass variables in scss/config/_defaults.scss to define its defaults.
$input-addon-fg-color: $form-idle-fg-active;
$input-addon-bg-image: linear-gradient(var(--default-dim-slight), var(--default-dim-slight));
$input-addon-bg-color: $form-idle-bg-regular;
$input-addon-border-color: $form-idle-border-color;The forms overview lists the Sass variables shared by all form elements.
Design tokens
Input groups have no tokens of their own. The forms overview lists the design tokens shared by all form elements.