Skip to the page content

Basic form fields

Every basic field type, from text and formatted fields to selects, choices, steppers and input groups, ready to copy.

24 field types

Text input

The plain single-line field and every state it comes in: with help text, with suggestions from a list, read-only, plain text, disabled, valid and invalid, and the three sizes. Use it for names, references and anything without a more specific type above.

Text fields
As it should appear on the parcel.
Suggestions appear as you type. Any other text is still allowed.
Ask your account manager to change it.
That name is free to use.
Enter the name for the parcel.
Three sizes
Show code
<input type="text" class="form-control" aria-describedby="help">
<input type="text" class="form-control" list="industries" data-basalt-combobox data-noun="industry">
<datalist id="industries"><option value="Pet care"></option>…</datalist>
<input type="text" class="form-control" readonly>
<input type="text" class="form-control-plaintext" readonly>
<input type="text" class="form-control" disabled>
<input type="text" class="form-control is-valid" aria-describedby="ok">
<div class="valid-feedback" id="ok">That name is free to use.</div>
<input type="text" class="form-control is-invalid" aria-invalid="true" aria-describedby="err">
<div class="invalid-feedback" id="err">Enter the name for the parcel.</div>
<input class="form-control form-control-sm"> <input class="form-control form-control-lg">

Floating labels

The label sits inside the field and moves up once there is a value, which keeps a long form compact. Works on text, email, select and textarea. Give each field a placeholder, which stays hidden, and keep the label short.

Text fields

Show code
<div class="form-floating">
  <input type="email" class="form-control" id="email" placeholder="Work email">
  <label for="email">Work email</label>
</div>
<div class="form-floating">
  <select class="form-select" id="type"><option>Home care</option></select>
  <label for="type">Type of business</label>
</div>
<div class="form-floating">
  <textarea class="form-control fb-floating-area" id="notes" placeholder="Notes"></textarea>
  <label for="notes">Anything else</label>
</div>

Textarea

For text that runs past one line. It can grow with what you write and count down to a limit, take quick phrases from buttons underneath, or be read-only so people can see it but not change it.

Text fields
98 characters left
Click a phrase to add it, click again to take it out.
Can be selected and copied, not edited.
Show code
<textarea class="form-control" id="msg" rows="2" maxlength="160"
          aria-describedby="dm-count"></textarea>
<div id="dm-count">160 characters left</div>

// Grow with the text
msg.addEventListener('input', () => {
  msg.style.height = 'auto';
  msg.style.height = msg.scrollHeight + 'px';
});

<textarea class="form-control" readonly>…</textarea>

Email field

An email input that is checked when you leave it, with a message that says what is missing. It also spots common domain typos and offers the fix as a button. With multiple set, one field takes a comma-separated list and checks each address.

Text fields
Try connie@gmial.com or connie@example.
Separate addresses with commas.
Show code
<input type="email" class="form-control" id="email" autocomplete="email"
       spellcheck="false" aria-describedby="email-err">
<div class="invalid-feedback" id="email-err">Add the end of the address, like .com</div>
<p hidden>Did you mean <button type="button">connie@gmail.com</button>?</p>

<!-- Several addresses in one field -->
<input type="email" class="form-control" multiple>

Password with strength meter

A password field with a show and hide button, a four-step strength bar and a checklist that checks off as you type. The confirm field says when the two match, and saving is blocked until every point is met.

Text fields

Strength: not set

  • At least 10 characters
  • Upper and lower case letters
  • A number or symbol
  • No common words like "password"

Show code
<div class="input-group">
  <input type="password" class="form-control" id="pass"
         autocomplete="new-password" aria-describedby="rules">
  <button class="btn btn-outline-secondary" type="button"
          aria-controls="pass" aria-pressed="false">Show</button>
</div>
<div class="fb-meter" data-level="3" aria-hidden="true">
  <span></span><span></span><span></span><span></span>
</div>
<p aria-live="polite">Strength: good</p>
<ul id="rules"><li>At least 10 characters</li>…</ul>

Select

For picking from a fixed list, in a list styled to match the page. Options can carry an icon, a color dot or a line of detail, sit under group headings, or be picked several at a time as chips. The browser's select stays underneath, so the value, required and form reset work as usual. A disabled select should say why in its help text.

Selects and tags
2 picked. Pick as many as you like.
Payment terms are set by your account manager.
Choose a delivery day.
Three sizes
Show code
<!-- Plain: any .form-select gets the styled list -->
<select class="form-select" id="plan"><option>Basic</option><option>Pro</option></select>

<!-- An icon, a color dot or a line of detail on each option -->
<option data-icon="heart">Pet care</option>
<option data-dot="success">Paid</option>
<option data-hint="Order by 2pm for delivery tomorrow">Next day</option>

<!-- Grouped -->
<select class="form-select" id="product">
  <optgroup label="Tailoring"><option>Blazer</option></optgroup>
  <optgroup label="Evening"><option selected>Organza dress</option></optgroup>
</select>

<!-- Several at once, shown as chips -->
<select class="form-select" multiple data-placeholder="Pick the skills this team member has">…</select>

<!-- Disabled and invalid -->
<select class="form-select" disabled aria-describedby="why">…</select>
<select class="form-select is-invalid" aria-invalid="true" aria-describedby="err">
  <option value="" selected disabled hidden>Choose a day</option>…
</select>
<div class="invalid-feedback" id="err">Choose a delivery day.</div>

<!-- Sizes -->
<select class="form-select form-select-sm">…</select>
<select class="form-select form-select-lg">…</select>

<!-- Keep the browser's own menu for one select -->
<select class="form-select" data-basalt-native>…</select>

Searchable select

A select with a search box at the top of its list. Type to narrow it, arrow keys move, Enter picks and Escape closes, and a line says so when nothing matches. Reach for it once a list passes about ten options.

Selects and tags
The search matches the name or the industry, so "pet care" works too.

Nothing picked yet.

Show code
<select class="form-select" id="customer" data-basalt-select="search"
        data-search-placeholder="Find a customer">
  <option value="" selected disabled hidden>Choose a customer</option>
  <optgroup label="Northeast">
    <option data-hint="Home care · 42 seats">Oakhaven Studio</option>
    <option data-hint="Home care · 31 seats">Northgate Analytics</option>
  </optgroup>
</select>

Tag input

Free entry that turns each word or phrase into a removable tag, for keywords, labels or recipients. Enter or comma adds one, Backspace removes the last, a repeat is refused with a note, and at its limit the field locks. A hidden input carries the list as one value.

Selects and tags
Key safe After hours Repeat visit
Enter or comma adds one. Backspace removes the last.

Sent as Key safe,After hours,Repeat visit

Dog on site No parking Steep stairs
Remove one to add another.
Show code
<div class="basalt-tags" data-basalt-tags data-max="6"
     data-full-placeholder="Six tags is the limit">
  <span class="basalt-tags-tag" data-value="Key safe">Key safe</span>
  <input type="text" class="basalt-tags-input" id="tags" placeholder="Add a tag">
</div>
<input type="hidden" name="tags" data-basalt-tags-value>
<span data-basalt-tags-count></span>

// A repeat fires an event you can answer
box.addEventListener('basalt:tags-duplicate', (e) => note(e.detail.value + ' is already there.'));

Tile checkboxes

A bigger, rounded-square check for grids and settings, where a stock checkbox is too small to aim at. It comes in four sizes and works for radios too. The real input stays inside, so Space, Tab and screen readers behave as usual.

Choices
Sizes: sm, md, lg and xl
With a label, tones and states
As radios, one choice
In a grid: alerts by channel
New sign-up Failed payment Weekly report
Show code
<label class="basalt-tick basalt-tick-lg">
  <input type="checkbox" checked>
  <span class="basalt-tick-box"><i class="bi bi-check-lg" aria-hidden="true"></i></span>
  <span class="basalt-tick-label">Share usage data</span>
</label>

<!-- No visible text? Name the input instead -->
<input type="checkbox" aria-label="Failed payment by email">

// Sizes: basalt-tick-sm, (md), --lg, --xl
// Tones: basalt-tick-success, --danger
// Half-checked: input.indeterminate = true;

Checkbox

For options that can be picked together, or a single yes or no. Checkboxes can carry help text, sit inline for short labels, and nest under a parent that goes half-checked when only some of its children are on. Disabled ones keep a readable label.

Choices
With help text: each piece comes in tissue, with a card and no price on it.
Parent and children

2 of 3 picked, so the parent is half-checked.

Inline
Show code
<div class="form-check">
  <input class="form-check-input" type="checkbox" id="all" aria-controls="kids">
  <label class="form-check-label" for="all">All tailoring</label>
</div>
<div id="kids"> …child checkboxes… </div>

// Half-checked when only some children are on
const on = kids.filter((k) => k.checked).length;
parent.checked = on === kids.length;
parent.indeterminate = on > 0 && on < kids.length;

Radio buttons

For one choice from a short list where every option should be visible. Stack them, put them inline when the labels are short, add a line of detail under each, or let one option switch on a field it needs. A sold-out option stays visible but disabled.

Choices
Stacked, one opens a field
With a line of detail
Signed in and ready to use out of the box.
Your admin enrolls it when it arrives.
Inline, with a disabled option
Show code
<fieldset>
  <legend class="form-label">When can we deliver?</legend>
  <div class="form-check">
    <input class="form-check-input" type="radio" name="when" id="when-any" checked>
    <label class="form-check-label" for="when-any">Any time of day</label>
  </div>
  <div class="form-check">
    <input class="form-check-input" type="radio" name="when" id="when-pick" aria-controls="slot">
    <label class="form-check-label" for="when-pick">A set window</label>
  </div>
  <select class="form-select" id="slot" disabled>…</select>
</fieldset>
<div class="form-check form-check-inline">…</div>

Switch

An on and off setting that takes effect straight away, with a line of help under each. One switch can reveal a field it needs, a master switch can turn the rest off, and a switch that cannot change is shown disabled.

Choices

A master switch: on, it turns off the three below.

The moment your parcel leaves us.

For the tailoring and accessories on your wish list.

Reveals the field it needs when switched on.

Disabled: receipts always go out.

Show code
<div class="form-check form-switch">
  <input class="form-check-input" type="checkbox" role="switch" id="ship"
         checked aria-describedby="ship-help">
  <label class="form-check-label" for="ship">Shipped, with tracking</label>
</div>
<p id="ship-help">The moment your parcel leaves us.</p>

<!-- Always on -->
<input class="form-check-input" type="checkbox" role="switch" checked disabled>

Choice tiles

Radios or checkboxes drawn as tiles, for a handful of options that each need an icon or a line of detail. Tones color a choice by what it leads to, the compact size fits days or sizes on one row, and a disabled tile turns dashed.

Choices
With an icon and a hint
Toned by outcome
Compact checkboxes

Delivering on Monday, Wednesday and Friday.

Show code
<div class="basalt-choices">
  <label class="basalt-choice">
    <input type="radio" name="plan" value="starter" checked>
    <i class="bi bi-person" aria-hidden="true"></i>Basic
    <span class="basalt-choice-hint">$15 a seat</span>
  </label>
</div>

<!-- Tones: --success, --warning, --danger -->
<label class="basalt-choice basalt-choice-danger"><input type="radio" name="oos">Refund it</label>

<!-- Compact, one line per tile -->
<div class="basalt-choices basalt-choices-compact">
  <label class="basalt-choice"><input type="checkbox" checked>Mon</label>
  <label class="basalt-choice"><input type="checkbox" disabled>Sun</label>
</div>

Number stepper

A number field with minus and plus buttons, for small counts. It reads min, max and step from the input, the arrow keys step too, a typed value is pulled back into range, and each button switches off at its limit. No browser spinners.

Numbers and dates
Blazers per order, 1 to 6.
Locations, 1 to 50.
Labels in stock, step="10".
Spare gift boxes, max 3, so plus is off.
Show code
<div class="basalt-stepper" data-basalt-stepper>
  <button type="button" class="basalt-stepper-btn" data-basalt-step="-1" aria-label="One fewer">…</button>
  <input type="number" class="basalt-stepper-input" id="blazers" value="2" min="1" max="6" step="1">
  <button type="button" class="basalt-stepper-btn" data-basalt-step="1" aria-label="One more">…</button>
</div>
<!-- Smaller: add basalt-stepper-sm. The input fires 'change' after every step. -->

Date and time inputs

The browser's own date, time and month fields, with its picker on each. Set min and max and the picker grays out the rest. The script here also pulls a typed date back into range, flags a time outside the window, and reads the choice back in words.

Numbers and dates
From tomorrow, up to 90 days ahead.
8am to 6pm, on the half hour.
For statements and billing.

Pick a date.

Show code
<input type="date" class="form-control" id="date" min="2026-09-29" max="2026-12-27">
<input type="time" class="form-control" id="time" min="08:00" max="18:00" step="1800">
<input type="month" class="form-control" id="month">

// A typed date can still land outside min and max, so pull it back
if (date.value < date.min) date.value = date.min;

Range slider

Picks a value between known limits by dragging. The single slider shows its value next to the label and help that changes with it. The two-handle version sets a low and a high end and never lets them cross.

Numbers and dates
20 staff
Mid-size team: plan for two schedulers.
Price, two handles $8 to $30
3 of 5
Disabled: set by the service contract.
Show code
<label class="form-label" for="staff">Staff on the road</label>
<output for="staff">20 staff</output>
<input type="range" class="form-range" id="staff" min="5" max="200" step="5" value="20">

<!-- Two handles: two ranges stacked on one track -->
<div class="fb-dual" role="group" aria-labelledby="price-label">
  <div class="fb-dual-track"><div class="fb-dual-fill"></div></div>
  <input type="range" min="0" max="40" value="8" aria-label="Lowest price">
  <input type="range" min="0" max="40" value="30" aria-label="Highest price">
</div>

Phone field

A phone number with its country code in a select. The number formats to that country's pattern as you type, a leading 0 is dropped outside the US, leaving the field checks the length, and the line below shows it in the international form you would store.

Formatted fields
US numbers have 10 digits.

Stored as nothing yet

Show code
<div class="input-group has-validation">
  <select class="form-select" aria-label="Country code">
    <option value="US">US +1</option><option value="GB">UK +44</option>
  </select>
  <input type="tel" class="form-control" id="tel" autocomplete="tel"
         aria-describedby="tel-help tel-err">
  <div class="invalid-feedback" id="tel-err">UK numbers have 10 digits after the 0.</div>
</div>

// Pattern per country: digits in each group, and the lengths allowed
const TEL = { US: { code: '+1', groups: [3, 3, 4], len: [10] },
              GB: { code: '+44', groups: [4, 6], len: [10] } };

Currency input

For prices and amounts. The symbol sits outside the field so it is never typed, letters are dropped, and leaving the field tidies the number to two decimals with thousands commas. The currency can be a fixed label or a select that changes the symbol.

Formatted fields
$ USD
$ USD

Margin 60% · $23.40 a unit

$
Type 2500 and leave the field: it becomes 2,500.00.
Show code
<div class="input-group">
  <span class="input-group-text">$</span>
  <input type="text" class="form-control" inputmode="decimal" value="39.00">
  <span class="input-group-text">USD</span>
</div>

// On blur: keep digits and one point, then format
const n = parseFloat(input.value.replace(/[^\d.]/g, ''));
input.value = n.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });

Postal code field

A postal code whose rules follow the country select. The label, the example and the check all change with it: a 5-digit ZIP, a UK postcode, an Irish Eircode. Leaving the field puts it in capitals with the space where it belongs, then marks it right or says what to fix.

Formatted fields
Looks right.
5 digits, or ZIP+4 like 10013-2290. Try the UK and type se13pa.
Show code
<select class="form-select" id="country" autocomplete="country">…</select>
<label class="form-label" for="post">ZIP code</label>
<input type="text" class="form-control" id="post" autocomplete="postal-code"
       aria-describedby="post-err">
<div class="invalid-feedback" id="post-err">Enter a ZIP code like 10013</div>

// One rule per country
const POST = {
  US: { label: 'ZIP code', re: /^\d{5}(-\d{4})?$/ },
  GB: { label: 'Postcode', re: /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i },
  IE: { label: 'Eircode',  re: /^[A-Z]\d[\dW] ?[A-Z\d]{4}$/i }
};

Card number

Payment card fields that format themselves. The number spaces into groups as you type, spots the card type from its first digits (Amex groups 4, 6, 5) and runs the standard checksum. The expiry adds its slash and refuses past dates, and the security code length follows the card type.

Formatted fields
Card
Try 4242 4242 4242 4242, or start with 37 for a 15-digit Amex.
3 digits, on the back.

Show code
<div class="input-group has-validation">
  <span class="input-group-text"><i class="bi bi-credit-card"></i> Visa</span>
  <input type="text" class="form-control" id="cc" inputmode="numeric"
         autocomplete="cc-number" aria-describedby="cc-help cc-err">
  <div class="invalid-feedback" id="cc-err">This number has a typo in it.</div>
</div>
<input type="text" inputmode="numeric" autocomplete="cc-exp" placeholder="MM / YY">
<input type="text" inputmode="numeric" autocomplete="cc-csc">

// Checksum every card number passes (Luhn)
const luhn = (d) => [...d].reverse().reduce((s, c, i) => {
  let n = +c; if (i % 2) { n *= 2; if (n > 9) n -= 9; } return s + n;
}, 0) % 10 === 0;

Slug field

The web address part of a page or product. It fills itself from the name until you edit it by hand, keeps to lower case letters, digits and dashes, and tidies on leave. Clear it and it follows the name again.

Formatted fields
/shop/
Follows the product name.
Show code
<div class="input-group">
  <span class="input-group-text">/shop/</span>
  <input type="text" class="form-control" id="slug" spellcheck="false">
</div>

/* "Robe Plissée 2" comes out as "robe-plissee-2" */
function toSlug(text) {
  return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase()
    .replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
}

Input groups

Text, icons, buttons or a small select attached to a field. Use them for fixed prefixes, units and one-click actions. The search field shows a clear button once it has text, and the copy button confirms in the help line.

Input groups
https://
days
A read-only field with a copy button.
Show code
<div class="input-group">
  <span class="input-group-text">https://</span>
  <input type="text" class="form-control" inputmode="url">
</div>
<div class="input-group">
  <input type="text" class="form-control" inputmode="decimal" value="680">
  <select class="form-select" aria-label="Weight unit"><option>g</option></select>
</div>
<div class="input-group">
  <input type="text" class="form-control" id="ref" readonly>
  <button class="btn btn-primary" type="button">Copy</button>
</div>

Code input

For codes people copy from somewhere else: vouchers, SKUs, booking references. It uses a monospaced face, turns letters to capitals as you type and switches spell check off. With an Apply button in the group, the answer shows inside it. Try SCULPT15, or SUMMER20 for an expired one.

Input groups

Capitals, digits and dashes only. Anything else is dropped as you type.
Show code
<div class="input-group has-validation">
  <input type="text" class="form-control font-monospace" id="code"
         autocomplete="off" spellcheck="false" aria-describedby="code-msg">
  <button class="btn btn-outline-secondary" type="submit">Apply</button>
  <div class="invalid-feedback" id="code-msg">SUMMER20 ended on August 31.</div>
</div>

// Capitals as you type, caret kept in place
input.addEventListener('input', () => {
  const s = input.selectionStart;
  input.value = input.value.toUpperCase();
  input.setSelectionRange(s, s);
});

Error summary

For forms longer than a few fields. Submitting with problems opens a box at the top that counts them and links each one to its field, while each field shows its own message. Fixing a field clears its line, and Reset clears everything.

Validation
Show code
<form novalidate>
  <div class="fb-errors" id="errors" role="group" tabindex="-1" aria-labelledby="errors-title" hidden>
    <h3 id="errors-title">There are 2 problems with your details</h3>
    <ul><li><a href="#email">Enter an email address</a></li>…</ul>
  </div>
  <label class="form-label" for="email">Email</label>
  <input type="email" class="form-control is-invalid" id="email" required
         aria-describedby="email-err" aria-invalid="true">
  <div class="invalid-feedback" id="email-err">Enter an email address</div>
</form>
// On submit with problems: fill the list, show the box, move focus to it.