Text inputs

Use a text input when you want the user to enter no more than a single line of information.

  • Content:
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/global.variables' as globalVariables;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/spacing.variables' as spacing;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/colours.variables' as colours;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/typography.variables' as typography;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/placeholder/focus.placeholders' as placeholders;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/line-heights.variables' as lineheight;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/font-sizes.variables' as fontSizes;
    @use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/font-weights.variables' as fontWeights;
    
    .ontario-input {
    	border: 2px solid colours.$ontario-colour-black;
    	border-radius: globalVariables.$global-radius;
    	box-sizing: border-box;
    	color: colours.$ontario-colour-black;
    	display: block;
    	font-size: fontSizes.$ontario-font-size-standard-body-text;
    	font-family: typography.$ontario-font-open-sans;
    	line-height: lineheight.$ontario-line-height-7;
    	margin: spacing.$spacing-0 spacing.$spacing-0 spacing.$spacing-7;
    	max-width: globalVariables.$standard-width;
    	width: globalVariables.$full-width;
    	padding: 0.625rem spacing.$spacing-4;
    	transition: box-shadow 0.1s ease-in-out;
    
    	&:focus,
    	&:active {
    		@extend %ontario-focus;
    	}
    }
    
    .ontario-input--2-char-width {
    	max-width: 8ex;
    	min-width: 8ex;
    }
    
    .ontario-input--3-char-width {
    	max-width: 10ex;
    	min-width: 10ex;
    }
    
    .ontario-input--4-char-width {
    	max-width: 12ex;
    	min-width: 12ex;
    }
    
    .ontario-input--5-char-width {
    	max-width: 14ex;
    	min-width: 14ex;
    }
    
    .ontario-input--7-char-width {
    	max-width: 17ex;
    	min-width: 17ex;
    }
    
    .ontario-input--10-char-width {
    	max-width: 23ex;
    	width: 100%;
    }
    
    .ontario-input--20-char-width {
    	max-width: 41ex;
    	width: 100%;
    }
    
    //General forms
    .ontario-form-group:last-of-type {
    	margin-bottom: 3rem;
    
    	.ontario-checkboxes,
    	.ontario-radios {
    		margin-bottom: spacing.$spacing-0;
    	}
    }
    
    //Date inputs
    
    .ontario-date__group {
    	display: flex;
    
    	label {
    		font-weight: fontWeights.$ontario-font-weights-semi-bold;
    	}
    
    	input {
    		margin-top: spacing.$spacing-4;
    	}
    }
    
    .ontario-date__group-input {
    	display: flex;
    	flex-direction: column;
    	margin-right: spacing.$spacing-5;
    }
    
    .ontario-date--error {
    	input {
    		border: 0.125rem solid colours.$ontario-colour-alert;
    	}
    }
    
  • URL: /components/raw/text-inputs/text-inputs.scss
  • Filesystem Path: fractal/components/components/form/text-inputs/text-inputs.scss
  • Size: 2.6 KB
  • Content:
    .ontario-input:focus,.ontario-input:active{box-shadow:0 0 0 4px #009adb;outline:4px solid transparent;transition:box-shadow .1s ease-in-out}.ontario-input{border:2px solid #1a1a1a;border-radius:4px;box-sizing:border-box;color:#1a1a1a;display:block;font-size:1rem;font-family:"Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;line-height:1.5;margin:0 0 2.5rem;max-width:48rem;width:100%;padding:.625rem 1rem;transition:box-shadow .1s ease-in-out}.ontario-input--2-char-width{max-width:8ex;min-width:8ex}.ontario-input--3-char-width{max-width:10ex;min-width:10ex}.ontario-input--4-char-width{max-width:12ex;min-width:12ex}.ontario-input--5-char-width{max-width:14ex;min-width:14ex}.ontario-input--7-char-width{max-width:17ex;min-width:17ex}.ontario-input--10-char-width{max-width:23ex;width:100%}.ontario-input--20-char-width{max-width:41ex;width:100%}.ontario-form-group:last-of-type{margin-bottom:3rem}.ontario-form-group:last-of-type .ontario-checkboxes,.ontario-form-group:last-of-type .ontario-radios{margin-bottom:0}.ontario-date__group{display:flex}.ontario-date__group label{font-weight:600}.ontario-date__group input{margin-top:1rem}.ontario-date__group-input{display:flex;flex-direction:column;margin-right:1.5rem}.ontario-date--error input{border:.125rem solid #cd0000}
  • URL: /components/raw/text-inputs/text-inputs.css
  • Filesystem Path: fractal/components/components/form/text-inputs/text-inputs.css
  • Size: 1.3 KB

Guiding principle: Give the user control.

When to use this component

A text input is a single-line field where the user can type in information.

Example


Enter your vehicle information section. Label: licence plate number (required). Hint text: for example, AAAA111. Empty text input field.

Use a text input if:

  • you want the user to enter no more than a single line of information
  • you need unique information from the user such as their name or phone number
  • it’s faster for the user to write out an answer rather than choose from a list

Do not use a text box if:

  • you want users to enter answers that are longer than one line (instead, consider a text area)
  • you want users to choose from a set list of responses such as yes or no (instead, consider radio buttons, checkboxes or dropdown lists

Use appropriately sized text inputs

All text inputs have a height of 48px.

Providing clear labels, hint text and specifying the width of the fields gives the user an indication on how to correctly fill out the input field. Choose the width of your text input field based on the type of information you’re asking for, but never limit the number of characters a user can input.

Known input length

Use fixed-width inputs for content that has a specific, known length, such as a postal code. Add room for 1 or 2 extra character spaces if users are likely to add spaces or dashes. Our standard fixed input widths are:

  • 2 characters (use for: date, month)
  • 3 characters (use for: area code, CVC on a credit card, age)
  • 4 characters (use for: year)
  • 7 characters (use for: postal code [includes extra character])
  • 8 characters (use for: licence plate)
  • 11 characters (use for: SIN [includes extra character])

Unknown input length

If you don’t know how many characters the user will need to input (for example, if you’re asking them for their name), make your text input 100% of the container.


Include the right keyboard code

Include the right code so the keyboard that comes up for mobile users matches the type of information you’re asking for. For example:

  • input type="text"shows the normal keyboard
  • input type="email" shows the normal keyboard plus a “@” and “.com”
  • input type="tel"shows the numeric 0 to 9 keypad
  • input type="text" inputmode="numeric" pattern="[0-9]" shows a keyboard with numbers and symbols
  • input type="date"shows the date selector
  • input type="datetime" shows the date and time selector
  • input type="month" shows the month and year selector

Let users choose formatting

Let users input information in any format and reformat it as needed for your database on the backend. For example, if you’re asking for a postal code, let users type it in upper- or lowercase, with or without spaces and dashes so any of these will be accepted:

  • A1A1A1
  • A1A-1A1
  • A1A 1A1
  • a1A 1a1

Only reformat information on the backend – don’t change how it appears to the user.


Leave text input fields blank

Do not put a label or hint text in the text field itself. Using “placeholder text” like this is not a good practice from a usability or accessibility perspective because it disappears when users start typing.

Do not put placeholder text inside the text field


Label: full name (required). Text input field showing enter your full name as placeholder text.

Additional technical specifications

In general, give the user control of what they’re entering and how they enter it.

Do:

  • always include an associated label with a matching ID above a text box
  • include hint text only if needed
  • left-align text areas (as well as their labels and hint text)
  • usually stack text inputs vertically
    • exception: sometimes it may make sense to include text inputs next to each outer, such as the birth/year/month inputs when asking for someone’s birthday
  • allow the user to:
    • copy and paste text
    • input any characters (although this doesn’t mean they can submit any type of character)
    • make their answer as long as they want (although they may get an error)
  • enable autofill
    • for example, if a user has their address stored in their web browser so it fills in address form fields automatically, let this happen
  • use one input field, rather than breaking a data element into multiple input fields
    • for example, use a single field for a credit card number, rather than breaking it into four fields

Do this:


One input field labelled 'credit card number (required)'.

Don't do this:


Input field separated into 4 input fields labelled 'credit card number (required)'

Don’t:

  • limit the number or type of characters the user can input
    • instead, give clear instructions and/or an error message if needed
  • use auto-tab, which is automatically moving the user’s cursor to the next text input

If you have any questions or feedback, please get in touch.