form-elements.mdx 18 KB

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