Should Bootstrap Forms Use Placeholders or Labels?

Should Bootstrap Forms Use Placeholders or Labels?

You have a signup or checkout form where every field shows its purpose as grey text inside the empty box. It looks tidy in the mockup. Then someone types into the third field, forgets what it was for, and may have to clear it to see the hint again.

Use a persistent, associated label for what each Bootstrap field is. Keep the placeholder for a short example only, and put any rule the user needs while typing in visible text under the field, linked with aria-describedby.

This post is for front-end developers and agency maintainers fixing or building Bootstrap forms. It shows the markup for a standard field, a floating label, a range slider and an error state, then a short test you can run before shipping.

Key Takeaways

  • The HTML spec defines a placeholder as a hint for an empty control and says to use a label for the field’s purpose, so a placeholder-only field is the wrong default.
  • A floating label is still a real label, but the DOM order is different in Bootstrap 5.3 (input first) and Bootstrap 6 (label first), so check which CSS is loaded before pasting.
  • A range slider needs a label for its purpose and persistent text for its scale, because tick captions depend on how the browser and plugin render them.
  • A red border is not an error message. Give each error visible text and connect it to the field with aria-describedby and aria-invalid="true".
  • Lighthouse only covers part of this. Tab through the form, read the computed name in DevTools and listen to it once with a screen reader.

Should Bootstrap forms use placeholders or labels?

Bootstrap forms should use a visible label to name each field and a placeholder only as an optional example, because the placeholder disappears the moment the user types.

Comparison of a field with only a placeholder and a field with a label across empty, filled and error states

The HTML spec describes placeholder as a short hint for an empty control and tells authors to use a label for the field’s purpose. The W3C’s form instructions tutorial says the same thing from the user’s side: placeholder text can supplement a label, and anything people need while entering or checking a response belongs in persistent text.

I think this is one of the few accessibility questions with a clear answer. The only real debate is how much extra the placeholder should carry, and my answer is very little. Here is how I split the jobs:

Job Use Visible when
Name the field <label for> with .form-label Always
Show an example value placeholder Only while the field is empty
State a format or rule .form-text linked by aria-describedby Always
Explain a failure .invalid-feedback linked by aria-describedby plus aria-invalid After the error is detected

Takeaway: each job gets its own element, and the label and any instructions stay visible while the user types.

One honest caveat. The working draft of the HTML accessibility API mappings does list placeholder as a fallback source for the accessible name of some inputs, after associated labels and title. So a placeholder-only field is not always nameless to assistive tech. It still has no visible name once the field has a value, and I would not rely on that fallback.

How do I add a visible, accessible label to a Bootstrap input?

Give the input a unique id, put a label with a matching for next to it, and add .form-label and .form-control so Bootstrap styles both.

The W3C’s H44 technique is exactly this: the label’s for matches the control’s id. Put this Bootstrap 6 field inside a form with a submit button. The field with help text follows the Bootstrap 6 form overview:

<div class="form-field">
  <label class="form-label" for="receipt-email">Receipt email address (required)</label>
  <input class="form-control" type="email" id="receipt-email" name="email"
         placeholder="name@example.com" aria-describedby="receipt-email-hint" required>
  <p class="form-text" id="receipt-email-hint">Use the address where you want to receive your receipt.</p>
</div>

Four attributes do four different jobs:

  • id identifies the field or hint and must be unique on the page. The label’s for points to the field’s id.
  • name is the key used for the field’s value when the form is submitted.
  • for connects the label to the id, so clicking the label can also focus the field.
  • aria-describedby goes on the input and points to the hint’s id to add a description. You can list several ids, separated by spaces.

Validation stays free. A required email input is invalid when empty, and a non-empty malformed address is a type mismatch. A placeholder supplies neither a value nor a constraint, so it cannot do that work for you. Leave native validation on (no novalidate) and the browser reports the problem on a normal submit. Your server still has to validate what arrives, as the constraint validation docs point out. If you want custom messages and server errors on a Bootstrap 5 project, this validation guide goes further.

Can I ever hide the visible label?

Sometimes, for a search box next to a button labelled Search, where the context states the purpose. WCAG 3.3.2 (Labels or Instructions) allows context in appropriate cases, but it also explains that an aria-label alone can leave the visible guidance requirement unmet. For a signup, contact or checkout form, keep the label visible. That is a judgement call, and I would rather err on showing it.

How do floating labels work in Bootstrap 5 and 6?

For a text field, a Bootstrap floating label is a real label inside .form-floating that sits over the input and shrinks upward when the field has focus or a value, driven by a non-empty placeholder.

The stock styles use :placeholder-shown to detect an empty text field. Bootstrap 5.3 hides the placeholder text, so the label is the only thing readers see. Keep the placeholder so the label can return to its resting position.

The part that bites people is the order. In Bootstrap 5.3 the input comes first and the label second:

<div class="form-floating">
  <input class="form-control" type="email" id="floating-email-v5" name="email"
         placeholder="name@example.com">
  <label for="floating-email-v5">Email address</label>
</div>

Bootstrap 6 Alpha 1 changed that order, and the current v6 docs put the label first:

<div class="form-floating">
  <label for="floating-email-v6">Email address</label>
  <input class="form-control" type="email" id="floating-email-v6" name="email"
         placeholder="name@example.com">
</div>

In v6 the CSS relies on :has() and :placeholder-shown. The default placeholder is transparent on an empty, unfocused field and takes the normal placeholder colour when focused, and a prefilled value starts with the label already floated.

If your Bootstrap 5 floating labels broke after an upgrade, check the loaded CSS version first, then the DOM order. Bootstrap’s own versions page lists 5.3.9 as the latest stable release and 6.0.0-alpha.2 as the latest prerelease, so v6 is still an alpha. Do not assume v5’s input-first order, its direct .form-range class or its .was-validated hook carry over.

Should you use floating labels at all? Pick them if the form is short and the label text is brief, since a long label can get cropped inside the box. Pick a standard stacked label for long forms, long labels, or fields with hints. I have no study to quote on whether either converts better, so I will not pretend to.

A note for Canvas users. Canvas 8.1.0 moved from Bootstrap 5.3.8 to 6.0.0-alpha.1, so old Canvas 8.0 form markup is a poor reference for v6 structure. The Canvas Bootstrap 6 page has a 5 to 6 cheat sheet, but it documents an Alpha 1 foundation, so confirm the bundled version before you rely on anything added in Alpha 2.

How do I add labels to a Bootstrap range slider?

Label a Bootstrap range slider like any other field with a label and for, then explain its scale in persistent text, and treat tick captions as a bonus.

A native range cannot take a placeholder or required, and it can never be empty, so those habits do nothing here. Per the HTML range state, the defaults are min=0, max=100 and step=1, and with those defaults the starting value is the midpoint unless you set a value. That last point matters: an untouched slider already holds a value, so an unmodified range does not prove the user made a choice.

Bootstrap 6 changes the markup. Per the v6 range docs, .form-range wraps a native .form-range-input, the Range plugin fills the track and builds ticks from list and a matching datalist, each option’s label becomes a tick caption, and data-bs-bubble on the wrapper turns on the value bubble. Bootstrap 6 plugins ship as ES modules, so load matching Bootstrap CSS and the ES module bundle for the enhanced slider.

<div class="form-field">
  <label class="form-label" for="reminder-frequency">Reminder frequency</label>
  <div class="form-range" data-bs-bubble>
    <input class="form-range-input" type="range" id="reminder-frequency"
           name="frequency" min="0" max="2" step="1" value="1"
           list="reminder-ticks" aria-describedby="reminder-scale">
  </div>
  <p class="form-text" id="reminder-scale">0 means off, 1 means weekly, and 2 means daily.</p>
</div>
<datalist id="reminder-ticks">
  <option value="0" label="Off"></option>
  <option value="1" label="Weekly"></option>
  <option value="2" label="Daily"></option>
</datalist>

The sentence under the slider is deliberate. Tick captions and the bubble are visual, and datalist captions do not render the same way in every browser. The persistent text defines the scale whatever happens to the ticks. If you change the value or the tick setup from JavaScript on Alpha 2, import Range from the matching Bootstrap module and call Range.getOrCreateInstance(wrapper).update() with the .form-range element as wrapper to refresh the display, as the range methods docs describe.

In Bootstrap 5.3 the class goes straight on the input, <input type="range" class="form-range">, without a wrapper or a plugin, and it adds no bubble. The label and the scale sentence are identical in both versions, which is the point: those two do the real work.

How do I keep the label, hint and error working together?

Keep the label always visible, link the hint and the error message to the input with aria-describedby, and set aria-invalid=”true” on the field when it is in an error state.

WCAG 2.2 criterion 3.3.1 requires that an automatically detected error identifies the item in error and describes it in text. A red outline alone gives no text description. Here is the server-returned error render of a floating field in Bootstrap 6, following the v6 floating feedback example:

<div class="form-field">
  <div class="form-floating">
    <label for="work-email">Work email address</label>
    <input class="form-control is-invalid" type="email" id="work-email" name="email"
           placeholder="name@company.example" value="name@example.net" required
           aria-invalid="true" aria-describedby="work-email-hint work-email-error">
  </div>
  <p class="form-text" id="work-email-hint">Use your company email address.</p>
  <div class="invalid-feedback" id="work-email-error">Enter an email address from your company domain.</div>
</div>

The normal render of the same field leaves out is-invalid, aria-invalid and the error id in aria-describedby. The error text says what to do, not just that something failed. And the feedback sits after .form-floating within the parent .form-field. If you combine .input-group with .form-floating in v6, put the feedback outside the input group but still inside .form-field.

Two version traps while you are here:

  • Bootstrap 6 scopes opt-in client-side styling to data-bs-validate and :user-invalid, per its validation docs. Server state such as .is-invalid works without the attribute. Bootstrap 5 uses .was-validated instead.
  • Bootstrap 5.3 warns that its stock custom client-side validation styles and tooltips are not exposed to assistive tech, and recommends browser defaults or the server-side example. Treat a tooltip as decoration and keep the real message in the DOM.

If your client script swaps these nodes without a page reload, check separately that the new error is announced and that focus lands somewhere sensible. For a multi-step form that matters on every step, and the multi-step form guide covers moving focus between steps.

How do I check the form before shipping?

Test five states, empty, filled, cleared, invalid and corrected, with a keyboard, the DevTools accessibility pane, Lighthouse and one screen reader, because no single tool covers all of it.

The W3C’s preliminary checks are a sensible starting point. Then run this list on each form:

  1. Keyboard only. Tab and Shift+Tab through every field. The focus indicator must be visible and the focus order must preserve meaning and let you use the form. Use the arrow keys on the slider.
  2. Empty, filled, cleared. Is the label still visible after you type? Clear the field. Does the placeholder or floating label return correctly?
  3. Submit it invalid. Try leaving a required field empty, then try entering a bad email. Each error should name the field and say what to fix.
  4. DevTools. In Chrome, open the Elements panel and the Accessibility pane to see the accessibility tree and computed properties. Each input should show a name from its label and a description from its hint and error.
  5. Lighthouse. It does audit associated form labels, but its score leaves out manual audits. A clean run does not prove the form is usable.
  6. Screen reader. Move through the form once with NVDA, VoiceOver or whichever you have. Listen for the label, the relevant hint, the slider value and the error.
  7. Recheck after a server error. Submit, get the server’s error back, and run steps 1 to 4 again on that rendered page.

Takeaway: tools catch missing associations, and a manual pass can catch labels and instructions that are present but unhelpful.

One limit on all of this. I checked the code above against the documentation, not against every browser and screen reader pairing. Run the list on your own implementation to check how your browser and screen reader announce the placeholder, hint and error.

Your first step

Open the form with the most traffic and find any field whose only name is its placeholder. Give each one an id, a label for and a hint linked with aria-describedby, then move the old placeholder text into an example or into the hint. When that is done, each updated field names itself after the user starts typing, and the form is ready for the keyboard and screen reader pass above. If the form is on a static site, the contact form guide covers where the submission goes next.

Frequently Asked Questions

Should I use Bootstrap form labels instead of placeholders?

Yes for the field’s purpose. Use an associated, persistent label to name the field. A short placeholder can show an example, and format rules belong in visible help text that stays on screen while the user types.

Do Bootstrap input fields need visible labels?

As a default, yes. WCAG 3.3.2 lets context carry the purpose in some cases, such as a search box beside a Search button. For signup, contact and checkout forms, a visible label is the safer choice, and the field still needs a proper programmatic name.

What is the difference between Bootstrap placeholder text and a real label?

A label identifies the control and stays available once the field has a value. A placeholder is a hint for the empty state only. The HTML accessibility mappings draft lists it as a fallback accessible name for some controls.

How do I give Bootstrap form controls accessible labels?

Match the label’s for to a unique input id. Use aria-describedby for hint and error text, and add aria-invalid="true" to the field when you render an error state.

How do I add floating labels in Bootstrap 5?

Wrap a .form-control input with a non-empty placeholder and a matching label in .form-floating. In Bootstrap 5.3 the input goes first and the label second, and the stock CSS hides the placeholder text.

Why do my Bootstrap 5 floating labels fail after upgrading to Bootstrap 6?

Bootstrap 6 Alpha 1 and the current Alpha 2 docs put the label before the input, while 5.3 expects the input first. Check which CSS version is loaded, then swap the DOM order to match it.

How do I make a Bootstrap range slider with labels?

Give the input a visible label and a sentence that explains the scale. In Bootstrap 6 you can add tick captions from a datalist and a value bubble with data-bs-bubble. In 5.3 you put .form-range on the input itself.

Skip the setup and build it free

Spin up a complete Bootstrap 5 site, blog included, with Canvas Builder. No coding, no cost.

Share:
Rohit S
Rohit S

Rohit S builds Canvas at SemiColonWeb, the team behind the Canvas HTML Template, CanvasWP and CanvasBuilder AI.

More from the Canvas Blog