Pattern Library

Forms

Forms are intsrumental to how users provide information, access content, and engage with the online community at large. Forms can be difficult to use for all users, but creating accessible usable forms can make this interaction easier for everyone. Usable and accessible forms make the interactive conversation with users a more enjoyable experience for all. Here are some tips to improve the user experience (Usable + Accessible) of forms.

Text Input

Text inputs allow users to enter any combination of letters, numbers, or symbols. Text input boxes can span single or multiple lines. They are well suited for situations where the user's input is fairly unpredictable and there could be a wide variability in the user's answers. Don't use this form component when users have to choose from a specific set of options.

Best Practices

Helpful error message

HTML Code Snippet

CSS Code Snippet

/* Form components */

input[type="text"], input[type="email"], input[type="password"], input[type="tel"], textarea  {
  border: 2px solid #58068c;
  border-radius: 3px;
  padding: 8px 16px;
  background: #fff;
  font-size: 1em;
  margin: 0 0 20px 0
}


label {
  color: #353535;
  display: block;
  cursor: pointer;
  font-weight: 500;
  padding: 5px 0;
  margin: 0;
}


fieldset, legend {
	margin: 0;
}

legend {
	
	font-size: 1.1em;
	font-weight: 600;
}


.srch-container {
	display: inline-block;
	margin: .5em 0;
}

.srch-container input[type="search"] {
	border: 2px solid #58068c;
	border-radius: 3px;
	padding: 8px 16px;
  	background: #fff;
  	font-size: 1em;
	margin: 0 .3em 0 0;
}

.srch-container button {
	background: #58068c;
	color: #fff;
	padding: 10px 20px;
	line-height: 1.6;
	border-radius: 3px;
	border: none;
}

.error-message {
	color:#b50909 !important;    
	display: block;
	font-weight: 500;
	position: relative;
	top: -10px;
}

.error-icon {
	color:#b50909 !important;
	position: relative;
	top: 7px;
	padding-right: 2px;
}

.input-error {border: 3px solid #b50909 !important; margin-bottom: 8px !important; }

Checkboxes

Checkboxes allow users to select one or more options from a visible list. It's best to consider a radio button when a user can only select one option from a list.

Best Practices

Choose from the list of items

HTML Code Snippet

CSS Code Snippet

/* Begin Styled checkbox */
.checkbox {
	margin: -1em 0;
}

.checkbox.column {
  margin-top: -1.5rem;
  padding: 0 1rem 1rem; }
  .checkbox.column label {
    display: block; }

.checkbox input[type='checkbox'] {
  opacity: 0; }


.checkbox label {
  position: relative;
  padding: 0 3rem 0 2rem; }

.checkbox label::before,
.checkbox label::after {
  position: absolute;
  content: '';
  display: inline-block; }

.checkbox label::before {
  height: 22px;
  width: 22px;
  left: 0;
  top: 1px;
  background: #fff;
  border: 2px solid #353535;
  border-radius: 3px;
}

.checkbox label::after {
  left: 7px;
  top: 3px;
  width: 8px;
  height: 14px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg); }

.checkbox input[type='checkbox'] + label::after {
  content: none; }

.checkbox input[type='checkbox']:checked + label::after {
  content: ''; }

.checkbox input[type='checkbox']:checked + label::before {
  background: #58068c; }

.checkbox input[type='checkbox']:focus + label::before {
  outline: 3px solid #1ca2b0 !important;
  outline: auto 5px -webkit-focus-ring-color; }

/* End Styled checkbox */

Radio Buttons

Radio buttons are a great form element choice for when users need to select only one option out of a set of mutually exclusive choices.

Best Practices

Conventional radio buttons

Horizontal segmented controls

HTML Code Snippet

CSS Code Snippet

/* Begin Styled radio button */

.radio.column {
  margin-top: -1rem;
  padding: 0 1rem 1rem; }
  .radio.column label {
    display: block; }

.radio input[type='radio'] {
  opacity: 0; }

.radio label {
  position: relative;
  padding: 0 3rem 0 2rem; }

.radio label::before,
.radio label::after {
  position: absolute;
  content: '';
  display: inline-block; }

.radio label::before {
  height: 22px;
  width: 22px;
  left: 0;
  top: 1px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid #353535; }

.radio label::after {
  left: 4px;
  top: 5px;
  width: 13px;
  height: 13px;
  border: 7px solid #58068c;
  border-radius: 50%; }

.radio input[type='radio'] + label::after {
  content: none; }

.radio input[type='radio']:checked + label::after {
  content: ''; }

.radio input[type='radio']:focus + label::before {
  outline: 3px solid #1ca2b0 !important;
  outline: auto 5px -webkit-focus-ring-color; }

/* End Styled radio button */



/* Segmented Control */

.segmented_c {
	margin-bottom: .5em;
}

.segmented_c .btn.btn-secondary {
    color: #58068c;
    background-color: #fff;
	margin-right:0 !important;
	padding: 9px 20px;
}


.segmented_c .btn-secondary:not(:disabled):not(.disabled).active {
	outline: 3px solid #1ca2b0;
	background: #58068c;
	color: #fff;
}


.segmented_c .btn-secondary.focus, .segmented_c .btn-secondary:focus {
	outline: 3px solid #1ca2b0;
	box-shadow:0;
}

/* End Segmented Control */

Select Lists

The HTML <select> tag is used to create a drop down list of options, which appears when clicking on the form element and allows the user to choose one of the options. Select lists can be somewhat unwieldy, especially on mobile. They are difficult to navigate, they hide options by default, they don't support hierarchies, and they only enable selection not editing. If your list of options has less than 7 options, consider using radio buttons instead. You can also use a text field with auto-complete if you have more than 15 options in a list.

Best Practices

HTML Code Snippet

CSS Code Snippet

/* Custom select */

.select {
  position: relative;
  display: inline-block;
  margin-bottom: 15px;
  margin-left: -2px; }

.select select {
  display: inline-block;
  cursor: pointer;
  padding: 10px 45px 10px 10px;
  border: 2px solid #58068c;
  background: #fff;
  color: #353535;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  font-size: 1rem;
  border-radius: 3px;
  }

.select select:focus {
	outline: 3px solid #1ca2b0;	
}
  .select select:hover, .select select:focus {
    color: #464646;
    background: #fff; }
  .select select:disabled {
   color: #353535;
    pointer-events: none; }
  .select select:hover ~ .select__arrow,
  .select select:focus ~ .select__arrow {
    border-top-color: #464646; }
  .select select:disabled ~ .select__arrow {
    border-top-color: #f4f4f4; }

.select__arrow {
  position: absolute;
  top: 55px;
  right: 15px;
  width: 2px;
  height: 0;
  pointer-events: none;
  border-style: solid;
  border-width: 10px 8px 0;
  border-color: #58068c transparent transparent; 
}

/* Custom Select Ends */

Buttons

There are three types of buttons:

Use buttons for the most important actions you want users to take on your site, such as Form Submissions, Download, Sign up or Log out.

Best Practices