---
title: Forms
category: Guides
order: 5
relevantForAI: true
---
## Required Fields
InstUI form components display an asterisk (`*`) next to labels when the `isRequired` (or `required`) prop is set. Whenever a form contains required fields, you **must include a note** explaining what the asterisk means — typically "Fields marked with an asterisk (\*) are required."
> **Exception:** You can omit this note when the form's purpose is entirely self-evident — for example, a standard login screen where it is obvious that both the email and password fields are required.
```ts
---
type: example
---
const RequiredFieldsExample = () => {
return (
Fields marked with an asterisk (*) are required.
)
}
render()
```
## Error Messages
InstUI offers a range of form elements and all of them have a similar API to handle error/hint/success messages. These components use the `messages` prop with the following type definition:
```ts
---
type: code
---
type FormMessages = {
type:
| 'error'
| 'hint'
| 'success'
| 'screenreader-only'
text: React.ReactNode
}[]
```
So a basic example would look something like this:
```ts
---
type: example
---
const PasswordExample = () => {
const [password, setPassword] = useState('')
const messages = password.length < 6
? [{type: 'error', text: 'Password have to be at least 6 characters long!'}]
: []
return (
{ setPassword(value) }}
/>
)
}
render()
```
```js
---
type: embed
---
The following section describes behavior introduced in v11.7: the updated error type and the required asterisk feature. If you are viewing the v11.6 version, switch to v11.7 to see these features working correctly.
```
The `error` type has been updated to meet accessibility requirements with proper icons and visual styling. Previously, there was a `newError` type that provided this enhanced behavior, but it has been consolidated into the standard `error` type for consistency. `newError` has been deprecated.
We also introduced the "required asterisk" which displays an `*` character next to field labels that are required. This update applies to **all** InstUI form components, so if you were relying on a custom solution for this feature before, you need to remove that to avoid having double asterisks.
Here are examples with different form components:
```ts
---
type: example
---
const Example = () => {
const [showError, setShowError] = useState(true)
const [showLongError, setShowLongError] = useState(false)
const [isRequired, setIsRequired] = useState(true)
const messages = showError
? [{type: 'error', text: showLongError ? 'Long error. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos voluptas, esse commodi eos facilis voluptatibus harum exercitationem. Et magni est consectetur, eveniet veniam unde! Molestiae labore libero sapiente ad ratione.' : 'Short error message'}]
: []
const handleSettingsChange = (v) => {
setShowError(v.includes('showError'))
setShowLongError(v.includes('showLongError'))
setIsRequired(v.includes('isRequired'))
}
return (
{isRequired && Fields marked with an asterisk (*) are required.}