Form controls

Form controls are styled <input> and <textarea> components which can be used to collect data of different types from the user.

Create amazing Typeform-like forms and pages just by writing Markdown!

Overview #

You can create form controls by adding the .form-control class to an <input> or <textarea>. You can read more about these elements on MDN: <input> and <textarea> (both links open in new tabs).

HTML
<div class="mb-3">
  <label for="example-input-1" class="form-label">Email</label>
  <input type="email" class="form-control" id="example-input-1" placeholder="name@example.com">
</div>
<div>
  <label for="example-textarea-1" class="form-label">Description</label>
  <textarea class="form-control" id="example-textarea-1" rows="3" placeholder="A short description about yourself"></textarea>
</div>

Sizing #

Create small and large form controls with the .form-control-sm and .form-control-lg classes respectively. These classes also work with the <textarea> element.

HTML
<!-- Small form control -->
<input type="text" class="form-control form-control-sm" placeholder="Example" aria-label="Small input example">

<!-- Default form control -->
<input type="text" class="form-control" placeholder="Example" aria-label="Default input example">

<!-- Large form control -->
<input type="text" class="form-control form-control-lg" placeholder="Example" aria-label="Large input example">

Disabled #

Disable a form control by adding the disabled attribute. This will change the appearance of the input, remove pointer events, and prevent focusing.

HTML
<!-- Disabled form controls -->
<div class="mb-3">
  <label for="example-input-2" class="form-label">Email</label>
  <input type="email" class="form-control" disabled id="example-input-2" value="chad@hotmail.com">
</div>
<div>
  <label for="example-textarea-2" class="form-label">Description</label>
  <textarea class="form-control" disabled id="example-textarea-2" rows="3">A pretty cool guy</textarea>
</div>

Read-only #

Add the readonly attribute to a form control to prevent modification of the value. Read-only inputs can still be focused and selected, while disabled inputs cannot.

HTML
<!-- Read-only form control -->
<input type="text" class="form-control" readonly value="Read-only example" aria-label="Read-only example">

Read-only plain text #

If you want to have readonly elements in your form styled as plain text, replace .form-control with .form-control-plaintext to remove the default form field styling and preserve the correct margin and padding.

HTML
<!-- Read-only plain text -->
<form>
  <div class="mb-2">
    <label for="example-input-3" class="visually-hidden">Email</label>
    <input type="text" readonly class="form-control-plaintext" id="example-input-3" value="steve@apple.com">
  </div>
  <div class="row g-2">
    <div class="col">
      <label for="example-input-4" class="visually-hidden">Password</label>
      <input type="password" class="form-control" id="example-input-4" placeholder="Password">
    </div>
    <div class="col-auto">
      <button type="submit" class="btn btn-primary">Confirm</button>
    </div>
  </div>
</form>

Form text #

Block-level or inline-level form text can be created using .form-text. If a block-level element is used, a top margin is added for easy spacing from the inputs above.

Must be 8-20 characters long, and contain letters, numbers, and at least one special character.
HTML
<!-- Form text (block-level) -->
<label for="example-input-5" class="form-label">Password</label>
<input type="password" id="example-input-5" class="form-control" aria-labelledby="password-help-block">
<div id="password-help-block" class="form-text">
  Must be 8-20 characters long, and contain letters, numbers, and at least one special character.
</div>

Inline text can use any typical inline HTML element (be it a <span>, <small>, or something else) with nothing more than the .form-text class.

Must be 8-20 characters long.
HTML
<!-- Form text (inline-level) -->
<div class="row g-2 align-items-center">
  <div class="col-auto">
    <label for="example-input-6" class="col-form-label">Password</label>
  </div>
  <div class="col-auto">
    <input type="password" id="example-input-6" class="form-control" aria-labelledby="password-help-inline">
  </div>
  <div class="col-auto">
    <span id="password-help-inline" class="form-text">Must be 8-20 characters long.</span>
  </div>
</div>

File input #

Set the type="file" and add .form-control to an <input> element to create a file input. You can also add the multiple attribute to allow more than one file as the input.

HTML
<!-- File input -->
<div class="mb-3">
  <label for="example-file-input-1" class="form-label">Upload your CV</label>
  <input class="form-control" type="file" id="example-file-input-1">
</div>

<!-- Multiple file input -->
<div>
  <label for="example-file-input-2" class="form-label">Attach additional files</label>
  <input class="form-control" type="file" id="example-file-input-2" multiple>
</div>

You can also disable file inputs using the disabled attribute, and also change sizing using .form-control-sm and .form-control-lg.

HTML
<!-- Disabled file input -->
<div class="mb-3">
  <label for="example-file-input-3" class="form-label">Disabled file input</label>
  <input class="form-control" type="file" disabled id="example-file-input-3">
</div>

<!-- Small file input -->
<div class="mb-3">
  <label for="example-file-input-4" class="form-label">Small file input</label>
  <input class="form-control form-control-sm" type="file" id="example-file-input-4">
</div>

<!-- Large file input -->
<div>
  <label for="example-file-input-5" class="form-label">Large file input</label>
  <input class="form-control form-control-lg" type="file" id="example-file-input-5">
</div>

Color #

Set the type="color" and add .form-control-color to an <input> element to create a color picker input box. We use the modifier class to set fixed height values and override some inconsistencies between browsers.

HTML
<!-- Color input -->
<label for="example-color-input" class="form-label">Color picker</label>
<input type="color" class="form-control form-control-color" id="example-color-input" value="#064fd8" title="Choose your color">

Datalists #

Datalists allow you to create a group of <option> tags that can be accessed (and autocompleted) from within an <input>. These are similar to <select> elements, but come with more menu styling limitations and differences. While most browsers and operating systems include some support for <datalist> elements, their styling is inconsistent at best.

Learn more about support for datalist elements (opens in new tab).

HTML
<!-- Datalist -->
<label for="example-input-7" class="form-label">Select state</label>
<input class="form-control" list="datalist-options" id="example-input-7" placeholder="Type to search...">
<datalist id="datalist-options">
  <option value="San Francisco">
  <option value="New York">
  <option value="Seattle">
  <option value="Los Angeles">
  <option value="Chicago">
</datalist>
Up next
Select

Help us grow

Our main goal is to make Halfmoon the go-to framework for building websites, dashboards and tools. If you believe in our mission, consider becoming a sponsor and help us grow.

You can email us directly if you have any queries. We are always happy to answer.

Subscribe for updates

We will notify you when the framework gets a substantial update. No spam ever.

Follow us on Twitter so that you can stay updated that way.