Text input
When to use this component
Use the text input component when you need to let users enter text that’s no longer than a single line, such as their name or phone number.
When not to use this component
Do not use the text input component if you need to let users enter longer answers that might span multiple lines. In this case, you should use the textarea component.
How it works
All text inputs must have visible labels; placeholder text is not an acceptable replacement for a label as it vanishes when users start typing.
Labels should be aligned above the text input they refer to. They should be short, direct and written in sentence case. Do not use colons at the end of labels.
If you’re asking just one question per page as recommended, you can set the contents of the <label>
as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.
You can use the above HTML.
If you’re asking more than one question on the page
If you’re asking more than one question on the page, do not set the contents of the <label>
as the page heading. Read more about asking multiple questions on question pages.
Use appropriately-sized text inputs
Help users understand what they should enter by making text inputs the right size for the content they’re intended for.
By default, the width of text inputs is fluid and will fit the full width of the container they are placed into.
If you want to make the input smaller, you can either use a fixed width input, or use the width override classes to create a smaller, fluid width input.
Fixed width inputs
Use fixed width inputs for content that has a specific, known length. Postcode inputs should be postcode-sized, telephone number inputs should be telephone number-sized.
The widths are designed for specific character lengths and to be consistent across a range of browsers. They include extra padding to fit icons that some browsers might insert into the input (for example to show or generate a password).
On fixed width inputs, the width will remain fixed on all screens unless it is wider than the viewport, in which case it will shrink to fit.
Fluid width inputs
Use the width override classes to reduce the width of an input in relation to its parent container, for example, to two-thirds.
Fluid width inputs will resize with the viewport.
Hint text
Use hint text for help that’s relevant to the majority of users, like how their information will be used, or where to find it.
When not to use hint text
Do not use long paragraphs and lists in hint text. Screen readers read out the entire text when users interact with the form element. This could frustrate users if the text is long.
Avoid links
Do not include links within hint text. While screen readers will read out the link text when describing the field, they will not tell users that the text is a link.
Numbers
Asking for whole numbers
If you’re asking the user to enter a whole number and you want to bring up the numeric keypad on a mobile device, set the inputmode
attribute to numeric
and the pattern
attribute to [0-9]*
. See how to do this in the HTML.
You should also turn off HTML5 validation to prevent browsers from validating the pattern attribute.
Asking for decimal numbers
If you’re asking the user to enter a number that might include decimal places, use input type="text"
without inputmode
or pattern
attributes.
Do not set the inputmode
attribute to decimal
as it causes some devices to bring up a keypad without a key for the decimal separator.
Error message
Error messages should be styled like this:
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
If the input is empty
Say ‘Εισάγετε [ό,τι είναι]’. For example, ‘Εισάγετε το μικρό σας όνομα’.
If the input is too long
Say ‘[ό,τι είναι] πρέπει να είναι [αριθμός] χαρακτήρες ή λιγότερο’. For example, ‘Η διεύθυνση πρέπει να είναι 35 χαρακτήρες ή λιγότερο’.
If the input is too short
Say ‘[ό,τι είναι] πρέπει να είναι [αριθμός] χαρακτήρες ή περισσότερο’. For example, ‘Το πλήρες όνομα πρέπει να είναι 2 χαρακτήρες ή περισσότερο’.
If the input has both a minimum and maximum length
Say ‘[ό,τι είναι] πρέπει να είναι από [αριθμός] μέχρι [αριθμός] χαρακτήρες. For example, ‘Το επώνυμο πρέπει να είναι από 2 μέχρι 35 χαρακτήρες.
If the input uses characters that are not allowed and you know what the characters are
Say ‘[ό,τι είναι] δεν πρέπει να περιλαμβάνει [χαρακτήρες]’. For example, ‘Η περιοχή δεν πρέπει να περιλαμβάνει è ή £’.
If the input uses characters that are not allowed and you do not know what the characters are
Say ‘[ό,τι είναι] πρέπει μόνο να περιλαμβάνει [λίστα από επιτρεπόμενους χαρακτήρες]’. For example, ‘Το πλήρες όνομα πρέπει μόνο να περιλαμβάνει τα γράμματα α μέχρι ω, παύλες, κενά και απόστροφους.
If the input is not a number
Say ‘[ό,τι είναι] πρέπει να είναι αρισθμός [προαιρετικό παράδειγμα]’. For example, ‘Οι εβδομαδιαίες ώρες εργασίας πρέπει να είναι αρισθμός, όπως 30’.
If the input requires a decimal, use a decimal in the example.
If the input allows both whole numbers and decimals, use both in the example.
If the input is not a whole number
Say ‘[ό,τι είναι] πρέπει να είναι ολόκληρος αριθμός [προαιρετικό παράδειγμα]’. For example, ‘Οι εβδομαδιαίες ώρες εργασίας πρέπει να είναι ολόκληρος αριθμός, όπως 30’.
If the number is too low
Say ‘[ό,τι είναι] πρέπει να είναι [ελάχιστο] ή περισσότερο’. For example, Οι εβδομαδιαίες ώρες πρέπει να είναι 16 ή περισσότερο’.
If the number is too high
Say ‘[ό,τι είναι] πρέπει να είναι [μέγιστο] ή λιγότερο’. For example, Οι εβδομαδιαίες ώρες πρέπει να είναι 99 ή λιγότερο’.
If the input must be between 2 numbers
Say ‘[ό,τι είναι] πρέπει να είναι μεταξύ [ελάχιστο] και [μέγιστο]’. For example, Οι εβδομαδιαίες ώρες πρέπει να είναι μεταξύ 16 και 99’.
If the input is an amount of money that needs decimals
Say ‘[ό,τι είναι] πρέπει να περιλαμβάνει λεπτά, όπως 123.45 or 156.00’. For example, ‘Το ποσό που εισπράττετε την εβδομάδα πρέπει να περιλαμβάνει pence, like 123.45 or 156.00’.
If the input is an amount of money that must not have decimals
Say ‘[ό,τι είναι] must not include pence, like 123 or 156’. For example, ‘Το ποσό που εισπράττετε την εβδομάδα must not include pence, like 123 or 156’.
Research on this component
Read a blog post about the problems we discovered with input type=”number”.
The prefix and suffix design has tested well in a number of services, but some users have been observed clicking on prefixes, on the assumption that this would do something.