Skip to content

Input ​

A text input with label, help text, invalid and disabled states, and an input-group icon example.

Installation ​

bash
npx bootcn add input
bash
pnpm dlx bootcn add input
bash
yarn dlx bootcn add input
bash
bunx --bun bootcn add input

The CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.

Usage ​

html
<div class="bootcn-field">
  <label for="name" class="form-label bootcn-field__label">Name</label>
  <input type="text" class="form-control bootcn-input" id="name" aria-describedby="name-help" />
  <p class="bootcn-field__help" id="name-help">Shown on your public profile.</p>
</div>

Invalid state ​

Add aria-invalid="true" and reference the error text with aria-describedby. The error uses Bootstrap's .invalid-feedback, shown by the component CSS:

html
<input
  type="email"
  class="form-control bootcn-input"
  id="email"
  aria-invalid="true"
  aria-describedby="email-help email-error"
/>
<p class="bootcn-field__help" id="email-help">We never share your email.</p>
<div class="invalid-feedback" id="email-error">Enter a valid email address.</div>

With an icon ​

Use Bootstrap's .input-group with an .input-group-text; mark the icon aria-hidden="true" and keep the input's own label.

Dependencies ​

  • Bootstrap 5.3+ CSS.
  • themes/tokens/tokens.css.

No JavaScript.

Accessibility ​

  • Every input needs a real <label> linked with for/id.
  • Help and error text are connected with aria-describedby, not placed as adjacent text only.
  • Use aria-invalid="true" for invalid state; do not rely on color alone.
  • Disabled inputs use the native disabled attribute.

Source ​

The exact files the CLI installs (input@1.1.0). View on GitHub · Report an issue

html
<div class="bootcn-field">
  <label for="bootcn-input-name" class="form-label bootcn-field__label">Name</label>
  <input
    type="text"
    class="form-control bootcn-input"
    id="bootcn-input-name"
    name="name"
    autocomplete="name"
    aria-describedby="bootcn-input-name-help"
    placeholder="Jane Doe"
  />
  <p class="bootcn-field__help" id="bootcn-input-name-help">Shown on your public profile.</p>
</div>

<div class="bootcn-field">
  <label for="bootcn-input-email" class="form-label bootcn-field__label">Email</label>
  <input
    type="email"
    class="form-control bootcn-input"
    id="bootcn-input-email"
    name="email"
    autocomplete="email"
    value="not-an-email"
    aria-invalid="true"
    aria-describedby="bootcn-input-email-help bootcn-input-email-error"
  />
  <p class="bootcn-field__help" id="bootcn-input-email-help">We never share your email.</p>
  <div class="invalid-feedback" id="bootcn-input-email-error">Enter a valid email address.</div>
</div>

<div class="bootcn-field">
  <label for="bootcn-input-disabled" class="form-label bootcn-field__label">Disabled</label>
  <input
    type="text"
    class="form-control bootcn-input"
    id="bootcn-input-disabled"
    value="Read only"
    disabled
  />
</div>

<div class="bootcn-field">
  <label for="bootcn-input-search" class="form-label bootcn-field__label">Search</label>
  <div class="input-group">
    <span class="input-group-text" aria-hidden="true">
      <svg
        width="16"
        height="16"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        aria-hidden="true"
        focusable="false"
      >
        <circle cx="11" cy="11" r="7" />
        <path d="m20 20-3.5-3.5" />
      </svg>
    </span>
    <input
      type="search"
      class="form-control bootcn-input"
      id="bootcn-input-search"
      name="search"
      placeholder="Search projects"
    />
  </div>
</div>
css
.bootcn-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.bootcn-field__label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
}

.bootcn-field__help {
  margin: 0;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

.bootcn-input {
  min-height: var(--bootcn-control-height);
  padding: var(--bootcn-control-padding-y) var(--bootcn-control-padding-x);
  border-color: var(--bootcn-input);
  border-radius: var(--bootcn-radius);
  background-color: transparent;
  box-shadow: var(--bootcn-shadow-sm);
  font-size: 1rem;
  transition:
    border-color var(--bootcn-transition),
    box-shadow var(--bootcn-transition);
}

.bootcn-input:focus {
  outline: 0;
  border-color: var(--bootcn-ring);
  box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}

.bootcn-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bootcn-input[aria-invalid='true'] {
  border-color: var(--bs-danger);
}

.bootcn-input[aria-invalid='true']:focus {
  border-color: var(--bs-danger);
  box-shadow: 0 0 0 3px rgba(var(--bs-danger-rgb), 0.2);
}

.bootcn-input[aria-invalid='true'] ~ .invalid-feedback {
  display: block;
}

/* Inside .input-group, Bootstrap's own rules square the inner corners. */

/* text-base on phones (no zoom on focus in iOS Safari), text-sm from md. */
@media (min-width: 768px) {
  .bootcn-input {
    font-size: var(--bootcn-control-font-size);
  }
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.