Bootstrap 4 Input Group – Material Design for Bootstrap
Mục Lục
Wrapping
Input groups wrap by default via flex-wrap: wrap
in order to accommodate custom form field validation
within an
input group. You may disable this with .flex-nowrap
.
@
Show code
Edit in sandbox
<div class="input-group flex-nowrap">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">@</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
</div>
Sizing
Add the relative form sizing classes to the .input-group
itself and contents within will
automatically resize—no need for repeating the form control size classes on each element.
Sizing on the individual input group elements isn’t supported.
Default input group
Small
Default
Large
Show code
Edit in sandbox
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Small</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">Default</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
</div>
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-lg">Large</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg">
</div>
Material input group
Small
Default
Large
Show code
Edit in sandbox
<div class="md-form input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text md-addon" id="inputGroupMaterial-sizing-sm">Small</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroupMaterial-sizing-sm">
</div>
<div class="md-form input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text md-addon" id="inputGroupMaterial-sizing-default">Default</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroupMaterial-sizing-default">
</div>
<div class="md-form input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text md-addon" id="inputGroupMaterial-sizing-lg">Large</span>
</div>
<input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroupMaterial-sizing-lg">
</div>
Multiple inputs
While multiple <input>
s are supported visually, validation styles are only
available for input groups with a single <input>
.
Default input group
First and last name
Show code
Edit in sandbox
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">First and last name</span>
</div>
<input type="text" aria-label="First name" class="form-control">
<input type="text" aria-label="Last name" class="form-control">
</div>
Material input group
First and last name
Show code
Edit in sandbox
<div class="md-form input-group">
<div class="input-group-prepend">
<span class="input-group-text md-addon">First and last name</span>
</div>
<input type="text" aria-label="First name" class="form-control" placeholder="Type sth">
<input type="text" aria-label="Last name" class="form-control" placeholder="Type sth">
</div>
Multiple addons
Multiple add-ons are supported and can be mixed with checkbox and radio input versions.
Default input group
$
0.00
$
0.00
Show code
Edit in sandbox
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
<span class="input-group-text">0.00</span>
</div>
<input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
</div>
<div class="input-group">
<input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
<div class="input-group-append">
<span class="input-group-text">$</span>
<span class="input-group-text">0.00</span>
</div>
</div>
Material input group
$
0.00
$
0.00
Show code
Edit in sandbox
<div class="md-form input-group mt-0 mb-3">
<div class="input-group-prepend">
<span class="input-group-text md-addon">$</span>
<span class="input-group-text md-addon">0.00</span>
</div>
<input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
</div>
<div class="md-form input-group mb-0">
<input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
<div class="input-group-append">
<span class="input-group-text md-addon">$</span>
<span class="input-group-text md-addon">0.00</span>
</div>
</div>
Button addons
Default input group
Show code
Edit in sandbox
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-md btn-outline-primary m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="button-addon1">Button</button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with button addon"
aria-describedby="button-addon1">
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username"
aria-describedby="button-addon2">
<div class="input-group-append">
<button class="btn btn-md btn-outline-default m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="button-addon2">Button</button>
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend" id="button-addon3">
<button class="btn btn-md btn-outline-secondary m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
<button class="btn btn-md btn-outline-secondary m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with two button addons"
aria-describedby="button-addon3">
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username with two button addons"
aria-describedby="button-addon4">
<div class="input-group-append" id="button-addon4">
<button class="btn btn-md btn-outline-info m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
<button class="btn btn-md btn-outline-info m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
</div>
</div>
Material input group
Show code
Edit in sandbox
<div class="md-form input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-md btn-default m-0 px-3" type="button" id="MaterialButton-addon1">Button</button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with button addon"
aria-describedby="MaterialButton-addon1">
</div>
<div class="md-form input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username"
aria-describedby="MaterialButton-addon2">
<div class="input-group-append">
<button class="btn btn-md btn-secondary m-0 px-3" type="button" id="MaterialButton-addon2">Button</button>
</div>
</div>
<div class="md-form input-group mb-3">
<div class="input-group-prepend" id="MaterialButton-addon3">
<button class="btn btn-md btn-info m-0 px-3" type="button">Button</button>
<button class="btn btn-md btn-info m-0 px-3" type="button">Button</button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with two button addons"
aria-describedby="MaterialButton-addon3">
</div>
<div class="md-form input-group">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username with two button addons"
aria-describedby="MaterialButton-addon4">
<div class="input-group-append" id="MaterialButton-addon4">
<button class="btn btn-md btn-primary m-0 px-3" type="button">Button</button>
<button class="btn btn-md btn-primary m-0 px-3" type="button">Button</button>
</div>
</div>
Custom forms
Input groups include support for custom selects and custom file inputs. Browser default versions of
these are not supported.
Custom select
Options
Options
Show code
Edit in sandbox
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Options</label>
</div>
<select class="browser-default custom-select" id="inputGroupSelect01">
<option selected>Choose...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
<div class="input-group mb-3">
<select class="browser-default custom-select" id="inputGroupSelect02">
<option selected>Choose...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<div class="input-group-append">
<label class="input-group-text" for="inputGroupSelect02">Options</label>
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-md btn-outline-mdb-color m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
</div>
<select class="browser-default custom-select" id="inputGroupSelect03" aria-label="Example select with button addon">
<option selected>Choose...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
<div class="input-group">
<select class="browser-default custom-select" id="inputGroupSelect04" aria-label="Example select with button addon">
<option selected>Choose...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<div class="input-group-append">
<button class="btn btn-md btn-outline-mdb-color m-0 px-3 py-2 z-depth-0 waves-effect" type="button">Button</button>
</div>
</div>
Custom file input
Upload
Choose file
Choose file
Upload
Choose file
Choose file
Show code
Edit in sandbox
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
<label class="custom-file-label" for="inputGroupFile01">Choose file</label>
</div>
</div>
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile02">
<label class="custom-file-label" for="inputGroupFile02" aria-describedby="inputGroupFileAddon02">Choose
file</label>
</div>
<div class="input-group-append">
<span class="input-group-text" id="inputGroupFileAddon02">Upload</span>
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-md btn-outline-mdb-color m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="inputGroupFileAddon03">Button</button>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile03" aria-describedby="inputGroupFileAddon03">
<label class="custom-file-label" for="inputGroupFile03">Choose file</label>
</div>
</div>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04">
<label class="custom-file-label" for="inputGroupFile04">Choose file</label>
</div>
<div class="input-group-append">
<button class="btn btn-md btn-outline-mdb-color m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="inputGroupFileAddon04">Button</button>
</div>
</div>
Accessibility
Screen readers will have trouble with your forms if you don’t include a label for every input. For these input
groups, ensure that any additional label or functionality is conveyed to assistive technologies.
The exact technique to be used (<label>
elements hidden using the .sr-only
class,
or use of the aria-label
and aria-labelledby
attributes, possibly in combination with
aria-describedby
) and what additional information will need to be conveyed will vary depending on the
exact type of interface widget you’re implementing. The examples in this section provide a few suggested,
case-specific approaches.