form-elements.mdx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. ---
  2. title: Form elements
  3. description: Forms are one of the most important types of interaction with a website or app. Since their aim is to enable users to make a purchase, subscribe to a service or sign up to create an account, it's important to make sure they are easy to complete and help increase conversion rates. Use the available elements to create forms which are well-structured and user-friendly.
  4. bootstrapLink: components/forms/
  5. libs: nouislider
  6. ---
  7. ## Classic inputs
  8. Use classic, user-friendly inputs, label them appropriately and include input placeholders that will help users avoid confusion when completing a form.
  9. ```html code example centered columns={1} height="20rem"
  10. <div class="mb-3">
  11. <label class="form-label">Text</label>
  12. <input type="text" class="form-control" name="example-text-input" placeholder="Input placeholder" />
  13. </div>
  14. <div class="mb-3">
  15. <label class="form-label">Password</label>
  16. <input type="text" class="form-control" name="example-password-input" placeholder="Input placeholder" />
  17. </div>
  18. ```
  19. ## Form control rounded
  20. Use the `form-control-rounded` class if you prefer form controls with rounded corners.
  21. ```html example centered columns={1} height="20rem"
  22. <div class="mb-3">
  23. <label class="form-label">Form control rounded</label>
  24. <input type="text" class="form-control form-control-rounded mb-2" name="Form control rounded" placeholder="Text.." />
  25. <div class="input-icon">
  26. <input type="text" value="" class="form-control form-control-rounded" placeholder="Search…" />
  27. <span class="input-icon-addon">
  28. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  29. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  30. <circle cx="10" cy="10" r="7" />
  31. <line x1="21" y1="21" x2="15" y2="15" />
  32. </svg>
  33. </span>
  34. </div>
  35. </div>
  36. ```
  37. ```html
  38. <div class="mb-3">
  39. <label class="form-label">Form control rounded</label>
  40. <input type="text" class="form-control form-control-rounded mb-2" name="Form control rounded" placeholder="Text.." />
  41. <div class="input-icon">
  42. <input type="text" value="" class="form-control form-control-rounded" placeholder="Search…" />
  43. <span class="input-icon-addon">
  44. <!-- SVG icon from http://tabler-icons.io/i/search -->
  45. <svg>...</svg>
  46. </span>
  47. </div>
  48. </div>
  49. ```
  50. ## Form control flush
  51. You can remove borders from your form control by adding the `form-control-flush` class.
  52. ```html code example centered columns={1} height="20rem"
  53. <div class="mb-3">
  54. <label class="form-label">Form control flush</label>
  55. <input type="text" class="form-control form-control-flush" name="Form control flush" placeholder="Text.." />
  56. </div>
  57. ```
  58. ## Input with icon
  59. Add icons to your input controls to suggest users what they should enter or inform them of the current state of a form element.
  60. ```html example code centered columns={1} height="20rem"
  61. <div class="mb-3">
  62. <label class="form-label">Icon input</label>
  63. <div class="input-icon mb-3">
  64. <input type="text" value="" class="form-control" placeholder="Search…" />
  65. <span class="input-icon-addon">
  66. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  67. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  68. <circle cx="10" cy="10" r="7" />
  69. <line x1="21" y1="21" x2="15" y2="15" />
  70. </svg>
  71. </span>
  72. </div>
  73. <div class="input-icon mb-3">
  74. <span class="input-icon-addon">
  75. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  76. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  77. <circle cx="12" cy="7" r="4" />
  78. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  79. </svg>
  80. </span>
  81. <input type="text" value="" class="form-control" placeholder="Username" />
  82. </div>
  83. </div>
  84. <div class="mb-3">
  85. <label class="form-label">Loader input</label>
  86. <div class="input-icon mb-3">
  87. <input type="text" value="" class="form-control" placeholder="Loading…" />
  88. <span class="input-icon-addon">
  89. <div class="spinner-border spinner-border-sm text-secondary" role="status"></div>
  90. </span>
  91. </div>
  92. <div class="input-icon mb-3">
  93. <span class="input-icon-addon">
  94. <div class="spinner-border spinner-border-sm text-secondary" role="status"></div>
  95. </span>
  96. <input type="text" value="" class="form-control" placeholder="Loading…" />
  97. </div>
  98. </div>
  99. ```
  100. ## Separated inputs
  101. Include an additional element in your input section, such as a button which can be used to submit the information enetered in the input control.
  102. ```html example code centered columns={1} height="20rem"
  103. <div class="mb-3">
  104. <label class="form-label">Separated inputs</label>
  105. <div class="row g-2">
  106. <div class="col">
  107. <input type="text" class="form-control" placeholder="Search for…" />
  108. </div>
  109. <div class="col-auto">
  110. <a href="#" class="btn btn-icon" aria-label="Button">
  111. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  112. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  113. <circle cx="10" cy="10" r="7" />
  114. <line x1="21" y1="21" x2="15" y2="15" />
  115. </svg>
  116. </a>
  117. </div>
  118. </div>
  119. </div>
  120. ```
  121. ## Textarea and select
  122. Use a multi-line text input control to enable users to enter longer pieces of text. The control will automatically adjust to the length of the text entered.
  123. Add one of the available selects - either a dropdown or a multiple choice select - to let users choose from a predefined set of options.
  124. ```html code example centered columns={1} height="30rem"
  125. <div class="mb-3">
  126. <label class="form-label">Textarea</label>
  127. <textarea class="form-control" name="example-textarea" placeholder="Textarea placeholder"></textarea>
  128. </div>
  129. <div class="mb-3">
  130. <div class="form-label">Select</div>
  131. <select class="form-select">
  132. <option value="1">One</option>
  133. <option value="2">Two</option>
  134. <option value="3">Three</option>
  135. </select>
  136. </div>
  137. <div class="mb-3">
  138. <div class="form-label">Select multiple</div>
  139. <select class="form-select" multiple>
  140. <option value="1">One</option>
  141. <option value="2">Two</option>
  142. <option value="3">Three</option>
  143. </select>
  144. </div>
  145. ```
  146. ## Input size
  147. Choose the size of an input control that will go well with your form design. Apart from the default size, you can also use small and large input controls.
  148. ```html code example centered columns={1} height="20rem"
  149. <div class="mb-3">
  150. <label class="form-label">Input sizing</label>
  151. <input class="form-control form-control-lg mb-2" type="text" placeholder=".form-control-lg" />
  152. <input class="form-control mb-2" type="text" placeholder="Default input" />
  153. <input class="form-control form-control-sm" type="text" placeholder=".form-control-sm" />
  154. </div>
  155. ```
  156. ## Datalists
  157. Use the `datalist` element to add an autocomplete feature to your input control. The list of available options will display once a user starts to type and will make it quicker to complete form sections.
  158. ```html example centered columns={1} height="20rem"
  159. <div class="mb-3">
  160. <label class="form-label">Datalist example</label>
  161. <input class="form-control" list="datalistOptions" placeholder="Type to search..." />
  162. <datalist id="datalistOptions">
  163. <option value="Aruba" />
  164. <option value="Afghanistan" />
  165. <option value="Angola" />
  166. <option value="Anguilla" />
  167. <option value="Albania" />
  168. <option value="Andorra" />
  169. <option value="United Arab Emirates" />
  170. <option value="Argentina" />
  171. <option value="Armenia" />
  172. <option value="American Samoa" />
  173. </datalist>
  174. </div>
  175. ```
  176. ## Toggle switches
  177. Use toggle switches for the elements of your form which require choosing between two opposing states.
  178. ```html example centered columns={1} height="20rem"
  179. <div class="mb-3">
  180. <div class="form-label">Toggle switches</div>
  181. <label class="form-check form-switch">
  182. <input class="form-check-input" type="checkbox" checked />
  183. <span class="form-check-label">Option 1</span>
  184. </label>
  185. <label class="form-check form-switch">
  186. <input class="form-check-input" type="checkbox" />
  187. <span class="form-check-label">Option 2</span>
  188. </label>
  189. <label class="form-check form-switch">
  190. <input class="form-check-input" type="checkbox" />
  191. <span class="form-check-label">Option 3</span>
  192. </label>
  193. </div>
  194. <div class="mb-3">
  195. <div class="form-label">Single switch</div>
  196. <label class="form-check form-switch">
  197. <input class="form-check-input" type="checkbox" />
  198. <span class="form-check-label">I agree with terms and conditions</span>
  199. </label>
  200. </div>
  201. ```
  202. ## Radios
  203. Use radio buttons for the parts of your form which require users to choose one option from a set of two or more mutually exclusive options.
  204. ```html example centered columns={1} height="20rem"
  205. <div class="mb-3">
  206. <div class="form-label">Radios</div>
  207. <div>
  208. <label class="form-check">
  209. <input class="form-check-input" type="radio" name="radios" checked />
  210. <span class="form-check-label">Option 1</span>
  211. </label>
  212. <label class="form-check">
  213. <input class="form-check-input" type="radio" name="radios" />
  214. <span class="form-check-label">Option 2</span>
  215. </label>
  216. <label class="form-check">
  217. <input class="form-check-input" type="radio" disabled />
  218. <span class="form-check-label">Option 3</span>
  219. </label>
  220. <label class="form-check">
  221. <input class="form-check-input" type="radio" checked disabled />
  222. <span class="form-check-label">Option 4</span>
  223. </label>
  224. </div>
  225. </div>
  226. ```
  227. ```html example centered columns={1} height="20rem"
  228. <div class="mb-3">
  229. <div class="form-label">Inline Radios</div>
  230. <div>
  231. <label class="form-check form-check-inline">
  232. <input class="form-check-input" type="radio" name="radios-inline" checked />
  233. <span class="form-check-label">Option 1</span>
  234. </label>
  235. <label class="form-check form-check-inline">
  236. <input class="form-check-input" type="radio" name="radios-inline" />
  237. <span class="form-check-label">Option 2</span>
  238. </label>
  239. <label class="form-check form-check-inline">
  240. <input class="form-check-input" type="radio" name="radios-inline" disabled />
  241. <span class="form-check-label">Option 3</span>
  242. </label>
  243. </div>
  244. </div>
  245. ```
  246. ## Checkboxes
  247. Use checkoxes if you want to allow users to select more than one option from a set of predefined options or to turn an option on or off.
  248. ```html example centered columns={1} height="20rem"
  249. <div class="mb-3">
  250. <div class="form-label">Checkboxes</div>
  251. <div>
  252. <label class="form-check">
  253. <input class="form-check-input" type="checkbox" />
  254. <span class="form-check-label">Checkbox input</span>
  255. </label>
  256. <label class="form-check">
  257. <input class="form-check-input" type="checkbox" disabled />
  258. <span class="form-check-label">Disabled checkbox input</span>
  259. </label>
  260. <label class="form-check">
  261. <input class="form-check-input" type="checkbox" checked />
  262. <span class="form-check-label">Checked checkbox input</span>
  263. </label>
  264. </div>
  265. </div>
  266. <div class="mb-3">
  267. <div class="form-label">Inline Checkboxes</div>
  268. <div>
  269. <label class="form-check form-check-inline">
  270. <input class="form-check-input" type="checkbox" />
  271. <span class="form-check-label">Option 1</span>
  272. </label>
  273. <label class="form-check form-check-inline">
  274. <input class="form-check-input" type="checkbox" disabled />
  275. <span class="form-check-label">Option 2</span>
  276. </label>
  277. <label class="form-check form-check-inline">
  278. <input class="form-check-input" type="checkbox" checked />
  279. <span class="form-check-label">Option 3</span>
  280. </label>
  281. </div>
  282. </div>
  283. ```
  284. ## Range input
  285. Add a range slider to make it possible for users to set a value or range, such as a price range or a time frame.
  286. ```html example centered columns={1} height="20rem"
  287. <div class="mb-3">
  288. <label class="form-label">Range input</label>
  289. <input type="range" class="form-range mb-2" value="40" min="0" max="100" step="10" />
  290. <div class="form-range mb-2" id="range-simple"></div>
  291. <div class="form-range mb-2" id="range-connect"></div>
  292. <div class="form-range mb-2 text-green" id="range-color"></div>
  293. </div>
  294. <script>
  295. document.addEventListener("DOMContentLoaded", function() {
  296. window.noUiSlider && (noUiSlider.create(document.getElementById('range-color'), {
  297. start: 40,
  298. connect: [true, false],
  299. step: 10,
  300. range: {
  301. min: 0,
  302. max: 100
  303. }
  304. }));
  305. });
  306. </script>
  307. ```
  308. ## Input group
  309. Create a group of input controls and place add-ons on either side of an input.
  310. ```html code example centered columns={1} height="20rem"
  311. <div class="mb-3">
  312. <label class="form-label">Input group</label>
  313. <div class="input-group mb-2">
  314. <span class="input-group-text">
  315. @
  316. </span>
  317. <input type="text" class="form-control" placeholder="username" autocomplete="off" />
  318. </div>
  319. <div class="input-group mb-2">
  320. <input type="text" class="form-control" placeholder="subdomain" autocomplete="off" />
  321. <span class="input-group-text">
  322. .tabler.io
  323. </span>
  324. </div>
  325. <div class="input-group">
  326. <span class="input-group-text">
  327. https://
  328. </span>
  329. <input type="text" class="form-control" placeholder="subdomain" autocomplete="off" />
  330. <span class="input-group-text">
  331. .tabler.io
  332. </span>
  333. </div>
  334. </div>
  335. ```
  336. ## Input with checkboxes or radios
  337. Add checkboxes or radio buttons on either side of your input control.
  338. ```html code example centered columns={1} height="20rem"
  339. <div class="mb-3">
  340. <label class="form-label">Input with checkbox or radios</label>
  341. <div class="input-group mb-2">
  342. <span class="input-group-text">
  343. <input class="form-check-input m-0" type="checkbox" checked />
  344. </span>
  345. <input type="text" class="form-control" autocomplete="off" />
  346. </div>
  347. <div class="input-group">
  348. <input type="text" class="form-control" autocomplete="off" />
  349. <span class="input-group-text">
  350. <input class="form-check-input m-0" type="radio" checked />
  351. </span>
  352. </div>
  353. </div>
  354. ```
  355. ## Input with prepended or appended text
  356. Add text to your input control, either before or after the text which is to be entered by a user.
  357. ```html code example centered columns={1} height="20rem"
  358. <div class="mb-3">
  359. <label class="form-label">Input with prepended text</label>
  360. <div class="input-group input-group-flat mb-2">
  361. <span class="input-group-text">
  362. https://tabler.io/users/
  363. </span>
  364. <input type="text" class="form-control ps-0" value="yourfancyusername" autocomplete="off" />
  365. </div>
  366. <div class="input-group input-group-flat">
  367. <input type="text" class="form-control text-end pe-0" value="yourfancydomain" autocomplete="off" />
  368. <span class="input-group-text">
  369. .tabler.io
  370. </span>
  371. </div>
  372. </div>
  373. ```
  374. ## Input with appended link
  375. Include a link in your input control to add a clickable element within the control.
  376. ```html code example centered columns={1} height="20rem"
  377. <div class="mb-3">
  378. <label class="form-label">Input with appended link</label>
  379. <div class="input-group input-group-flat">
  380. <input type="password" class="form-control" value="ultrastrongpassword" autocomplete="off" />
  381. <span class="input-group-text">
  382. <a href="#" class="input-group-link">Show password</a>
  383. </span>
  384. </div>
  385. </div>
  386. ```
  387. ## Input with appended `<kbd>`
  388. Include a `<kbd>` in your input control to add shortcut to the control.
  389. ```html code example centered columns={1}
  390. <div class="mb-3">
  391. <label class="form-label">Input with appended link</label>
  392. <div class="input-group input-group-flat">
  393. <input type="password" class="form-control" value="ultrastrongpassword" autocomplete="off" />
  394. <span class="input-group-text">
  395. <kbd>ctrl + K</kbd>
  396. </span>
  397. </div>
  398. </div>
  399. ```
  400. ## Input with appended icon links
  401. Add an icon link which you want to display at the end of your input control to visually represent actions which a user can take.
  402. ```html example code centered columns={1} height="20rem"
  403. <div class="mb-3">
  404. <label class="form-label">Input with appended icon links</label>
  405. <div class="input-group input-group-flat">
  406. <input type="text" class="form-control" autocomplete="off" />
  407. <span class="input-group-text">
  408. <a href="#" class="link-secondary" title="Clear search" data-bs-toggle="tooltip">
  409. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  410. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  411. <line x1="18" y1="6" x2="6" y2="18" />
  412. <line x1="6" y1="6" x2="18" y2="18" />
  413. </svg>
  414. </a>
  415. <a href="#" class="link-secondary ms-2" title="Search settings" data-bs-toggle="tooltip">
  416. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  417. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  418. <circle cx="6" cy="10" r="2" />
  419. <line x1="6" y1="4" x2="6" y2="8" />
  420. <line x1="6" y1="12" x2="6" y2="20" />
  421. <circle cx="12" cy="16" r="2" />
  422. <line x1="12" y1="4" x2="12" y2="14" />
  423. <line x1="12" y1="18" x2="12" y2="20" />
  424. <circle cx="18" cy="7" r="2" />
  425. <line x1="18" y1="4" x2="18" y2="5" />
  426. <line x1="18" y1="9" x2="18" y2="20" />
  427. </svg>
  428. </a>
  429. <a href="#" class="link-secondary ms-2 disabled" title="Add notification" data-bs-toggle="tooltip">
  430. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  431. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  432. <path d="M10 5a2 2 0 0 1 4 0a7 7 0 0 1 4 6v3a4 4 0 0 0 2 3h-16a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6" />
  433. <path d="M9 17v1a3 3 0 0 0 6 0v-1" />
  434. </svg>
  435. </a>
  436. </span>
  437. </div>
  438. </div>
  439. ```