
Form control HTML basics are essential for creating effective and user-friendly forms.
The most common form control elements are input, select, and textarea.
Input elements are used for single-line text input, while select elements are used for dropdown menus.
Textarea elements are used for multi-line text input.
A good practice is to use the autocomplete attribute to specify whether the input field should be auto-filled.
For example, autocomplete can be set to "on" or "off" to enable or disable auto-filling.
Consider reading: Is Html Used to Create Web Pages
Button Types
Buttons are an essential part of any form, and there are several types to choose from.
A submit button sends the form data to the server, and for button elements, omitting the type attribute results in a submit button by default.
There are also reset buttons that reset all form widgets to their default values.
Custom buttons can be created using JavaScript code.
The main difference between input and button elements is that actual button elements are much easier to style.
Explore further: Html Default Image
Form Elements
Form elements are the building blocks of a form in HTML, and they enable users to interact with the webpage by entering information. These elements can be categorized into different types.
There are several types of form controls that can be used to collect data, including text input controls, checkboxes, radio buttons, select box controls, and more. Let's take a look at some of the most common types:
- Text Input Controls: These include single-line text input, password input, and multi-line text input.
- Checkboxes Control: Used to accept multiple values.
- Radio Buttons Control: Used to accept a single value from a group of options.
- Select Box Control: Used to select one value from a list of options.
- File Select Box: Used to select a file from the user's device.
- Button Control: Used to submit the form or perform another action.
- Hidden Form Control: Used to store data without displaying it to the user.
Select Box
A select box is a versatile form element that lets users pick one or more options from a dropdown list. It's a convenient way to collect data from users.
You can create a select box using HTML code, as we'll see in the example. The code is straightforward and easy to understand.
A select box can be used to create a dropdown menu with multiple values, making it a great choice for forms that require users to select from a range of options. For instance, a dropdown menu with three values can be created using a simple HTML code.
In practice, a select box is useful for forms that need to collect data with multiple options, such as a survey or a registration form. It saves users time and effort by presenting them with a list of choices.
Check this out: Set up Html Mail Using Word
Datalists
Datalists are similar to select elements, but come with more menu styling limitations and differences.
Most browsers and operating systems include some support for datalist elements, but their styling is inconsistent at best.
Datalists allow you to create a group of options that can be accessed and autocompleted from within an input.
Intriguing read: Styling Html Lists
Form Control State
Form Control State is a crucial aspect of FormControl in HTML, and understanding it can help you provide better user feedback.
The FormControl object has six properties that describe its state: pristine, dirty, valid, invalid, touched, and untouched.
These properties can be used to display feedback to the user, such as error messages or hints.
Here are the six properties and their definitions in a list:
- Pristine: true when the user has not changed the element value
- Dirty: opposite of pristine — true when the user has changed the element value
- Valid: true when the element value is valid against all validation rules applied to the element
- Invalid: opposite of valid — true when the element value is not valid
- Touched: true when the user has put focus on the element (say clicked on it) and then removed the focus from the element (clicked away from it)
- Untouched: opposite of touched — means the user hasn’t put focus on the element or hasn’t removed that focus yet.
Control State Status
Control State Status is crucial when it comes to providing feedback to the user. You can use the six properties of the FormControl object to display feedback such as error messages or hints.
If this caught your attention, see: Html Feedback Form Send Email
The six properties are: pristine, dirty, valid, invalid, touched, and untouched. These properties can be set automatically by Angular as CSS classes on the form element.
Here's a quick rundown of each property:
- Pristine: true when the user hasn't changed the element value
- Dirty: opposite of pristine – true when the user has changed the element value
- Valid: true when the element value is valid against all validation rules applied to the element
- Invalid: opposite of valid – true when the element value is not valid
- Touched: true when the user has put focus on the element and then removed the focus
- Untouched: opposite of touched – means the user hasn’t put focus on the element or hasn’t removed that focus yet
These properties can be used to display feedback to the user in real-time. For example, if a user clears the text input (for which a value is required), the ng-invalid class will be applied, making the background color pink. If the user types anything in the input, it will become dirty, and the light gray background color will be applied.
Broaden your view: Html Tag B
Readonly Plain
Readonly plain text can be achieved by replacing .form-control with .form-control-plaintext. This removes the default form field styling and preserves the correct margin and padding.
If you want to style readonly inputs as plain text, you need to make this replacement. This is a simple way to keep the input's value from being modified, while still making it look like plain text.
The .form-control-plaintext class is specifically designed to remove the default form field styling, making it perfect for readonly plain text inputs.
Here's an interesting read: Image Styling Html
Form Control Updates
Form Control Updates are crucial to understanding how Angular forms work.
The FormControl value gets updated based on the updateOn property, which can be set to blur, submit, or change. The default behavior is change, which means the FormControl value updates in real-time as the user makes changes.
You can delay the FormControl update process by setting updateOn to blur or submit, which means the value will only update when the user loses focus or submits the form.
Here are the options for the updateOn property:
- blur — The FormControl value updates when the HTML element blur event is sent (element loses focus)
- submit — The FormControl value updates when the HTML element form is submitted.
- change — The default behavior. User updates are reflected in real-time as the FormControl value.
Determine Value Update Timing
You can delay the FormControl update process with the updateOn property, which is passed as a control option. This allows you to decide when the FormControl value gets updated.
There are three options to choose from: blur, submit, and change. The blur option updates the FormControl value when the HTML element blur event is sent, or when the element loses focus.
The submit option updates the FormControl value when the HTML element form is submitted. This is useful when you want to validate the form before submitting it.
If this caught your attention, see: Blur Background Html Css
The change option is the default behavior, and it updates the FormControl value in real-time as the user updates the form control. This means the user will see the updated value immediately.
Here are the three options summarized in a table for easy reference:
Resetting instead of clearing with default value
You can reset a form to its initial value instead of clearing it with the nonNullable control option. This is useful when editing existing data, such as a user's profile information.
The nonNullable option, also known as initialValueIsDefault, allows you to reset the form to its initial value rather than clearing the input. This is especially convenient in edit mode.
To try this out, make edits to the form control and then reset the form. You'll see that it reverts to the initial value rather than clearing the input. This behavior is demonstrated in the example below.
Here's a summary of the nonNullable option:
This option is useful in cases where you want to preserve the existing data and only reset the form to its initial state.
Subscribing to Updates Using Observables
Subscribing to updates using observables is a powerful way to react to form changes in real-time. This can be especially useful when working with complex forms or when you need to trigger an HTTP request or filter a list as the user interacts with the form.
The FormControl object has two public properties that emit updates as the user interacts with the form: valueChanges and statusChanges. These properties are observables, which means you can subscribe to them to receive updates.
You can subscribe to these observables in your component class or using the async pipe in your HTML template. This allows you to react to form updates as they happen.
Here's a quick rundown of the observables:
- valueChanges — Emits all value updates as soon as they happen
- statusChanges — Emits all status updates (VALID or INVALID) as the user changes the form control value
By subscribing to these observables, you can create a more dynamic and responsive form experience for your users.
Form Control Properties
Form control properties are a crucial aspect of FormControl in Angular. These properties help you understand the state of a control and provide visual feedback to the user.
You might enjoy: Html Cache Control
The six properties of FormControl are: pristine, dirty, valid, invalid, touched, and untouched. These properties are automatically set by Angular as CSS classes on the form element.
Here's a breakdown of each property:
- Pristine: true when the user has not changed the element value.
- Dirty: opposite of pristine — true when the user has changed the element value.
- Valid: true when the element value is valid against all validation rules applied to the element.
- Invalid: opposite of valid — true when the element value is not valid.
- Touched: true when the user has put focus on the element (say clicked on it) and then removed the focus from the element (clicked away from it).
- Untouched: opposite of touched — means the user hasn’t put focus on the element or hasn’t removed that focus yet.
Sizing
Sizing is a crucial aspect of form control properties, and it's easier than you think. You can set heights using classes like .form-control-lg and .form-control-sm.
These classes are designed to help you quickly adjust the size of your form controls to suit your needs.
Readonly
Adding the readonly boolean attribute to an input can prevent modification of its value. This is a useful feature for forms where you want to display information but don't want it to be edited by the user.
Readonly inputs can still be focused and selected, which is different from disabled inputs that cannot be interacted with at all.
Discover more: Html Input Readonly
Datetime
The datetime control in HTML is a powerful tool for representing date and time. It encodes the date and time according to ISO 8601 with the time zone set to UTC.
This means that the datetime control includes year, month, day, hour, minute, second, and fractions of a second. It's a very specific and detailed way to represent time.
Using the datetime control allows you to display date and time with a high level of precision. You can also use the datetime-local control which will display date and time with no time zone information.
The datetime control is a great option for forms that require a specific date and time to be entered by the user.
A fresh viewpoint: Html Datetime
Time
Time is a fundamental aspect of form control properties, and the HTML time control is a crucial element in specifying time values.
The HTML time control is used to specify hours, minutes, seconds, and fractional seconds, all encoded according to the ISO 8601 standard.
This standard ensures that time values are consistently formatted and easily understood across different systems and applications.
By using the HTML time control, developers can ensure that their forms accurately capture and display time values.
For example, the time control can be used to specify the time of day, down to the second, allowing for precise scheduling and coordination.
Discover more: Is Html Still Used

Email control is a type that accepts only email values. It's used for input fields that should contain an email address, like [email protected].
If you try to submit a simple text, email control will force you to enter a valid email address. This ensures that only correct email formats are accepted.
Recommended read: Html Blank to Address in Mailto
Form Control Attributes
A form control's value is its internal state, which might not match the user's current input. This is because the control's value is determined by its internal logic, not just the user's input.
For instance, if a user enters the word "three" into a numeric field, the control's value will remain unchanged. This is because the control's value is not just a simple reflection of the user's input.
Some form controls have a dirty value flag, which tracks the interaction between the value and default value. If this flag is false, the value mirrors the default value. If it's true, the default value is ignored.
A form control can be designated as mutable, which determines whether the user can modify the value or checkedness of the control. This designation affects whether the control can be automatically prefilled or not.
Expand your knowledge: Default Html
Url
The URL control is a specific type of input field that accepts only URL values. It's perfect for forms that require a website or online address.
If you try to submit a simple text, the URL control will force you to enter only a URL address, either in the http://www.example.com format or in the http://example.com format.
On a similar theme: How to Remove Html from Url
4.10.18 Infrastructure
A form control's value is its internal state, which might not match the user's current input.
This can happen when a user enters something like "three" into a numeric field that expects digits, and the control's value remains unchanged.
The input and textarea elements have a dirty value flag, which tracks the interaction between the value and default value.
If it's false, the value mirrors the default value, but if it's true, the default value is ignored.
Some form controls also have an optional value, but it's generally recommended to use the value attribute instead.
For more insights, see: Html Select Option Default
The select element doesn't have a value; instead, the selectedness of its option elements is what's used.
A form control can be designated as mutable, which determines whether the user can modify the value or checkedness of the control.
If a form-associated element is not associated with a form element, its form owner is said to be null.
A form-associated element has an associated parser inserted flag, which is set by default.
If a listed form-associated element has a form attribute specified, its value must be the ID of a form element in the element's tree.
4.10.19 Attributes
Form control attributes play a crucial role in determining the behavior and appearance of form elements.
The disabled attribute is used to disable a form element, making it unusable. This attribute can be applied to any form element, including input fields, buttons, and checkboxes.
The readonly attribute is used to make a form element read-only, allowing users to view its value but not edit it. This attribute is often used for form fields that require input but cannot be changed once set.
Discover more: Form Field Html
The autofocus attribute is used to automatically focus on a form element when the page loads. This attribute is commonly used to draw the user's attention to a specific form field.
The required attribute is used to specify that a form field must be filled out before the form can be submitted. This attribute is often used for fields that are essential to the form's functionality.
You might like: The Html Canvas Element Is Used to
4.10.22 Submission
Submission is a crucial aspect of form control attributes, and it's what happens after the user fills out a form and clicks the submit button. The form data is converted into the structure specified by the enctype, and then sent to the destination specified by the action using the given method.
The enctype attribute determines how the form data is encoded, with common values including application/x-www-form-urlencoded, multipart/form-data, and text/plain. The action attribute specifies the URL where the form data is sent, and the method attribute determines whether the form data is sent using HTTP GET or HTTP POST.
If this caught your attention, see: Get Method Html Form
If the user types in "cats" in the first field and "fur" in the second, and then hits the submit button, the user agent will load /find.cgi?t=cats&q=fur. This is an example of how the form data is converted into a URL query string.
The user agent will then send an HTTP POST request to the given URL, with the form data as the entity body. For example, the entity body might be something like "t=cats&q=fur". This is an example of how the form data is encoded and sent to the server.
The FormData object is a useful tool for working with form data, as it allows you to access the names and values of the form elements. You can use the FormData object to modify the form data before it is submitted, or to access the form data after it has been submitted.
The SubmitEvent object is returned when the form is submitted, and it provides information about the submit button that triggered the submission. The FormDataEvent object is also returned, and it provides a FormData object representing the names and values of the form elements.
You might enjoy: Python Read Html from Url
Example and Usage
Using FormControl without FormBuilder is a straightforward process, especially when dealing with single elements. You can create a FormControl object and bind it to the HTML element, eliminating the need for a ngModel directive or a FormBuilder service.
To do this, you'll need to create a FormControl object in your component class. For instance, if you have a single text input field, your component class might look something like this:
To access the value of that control, you can use myControl.value, as demonstrated in the complete code example below. By default, FormControl will update its value whenever the user changes the HTML form element value.
Here are some common form controls you can use to collect data using HTML form:
- Text Input Controls
- Checkboxes Control
- Radio Buttons Control
- Select Box Control
- File Select Box
- Button Control
- Hidden Form Control
- Datetime Controls
- Date Control
- Month Control
- Week Control
- Time Control
- Number Control
- Range Control
- Email Control
- URL Control
Example
You can create single-line text input fields by running a specific code. This code will display two single-line text input fields when executed.
In the example provided, the code is designed to take a single-line text input. Two single-line text input fields will be displayed on running the above code.
The code is straightforward and easy to understand.
Worth a look: Can Class Equal Two Things in Html
Single Element Usage

Using FormControl with a single element is a straightforward process. You can create a FormControl object and bind it to the HTML element directly.
In the component class, you only need to create a FormControl instance. The code is as simple as that.
You can access the value of the control with myControl.value, just like shown in the complete code example.
FormControl will update its value whenever the user changes the HTML form element value, no need to worry about that.
Here are the basic steps to follow:
By following these steps, you can easily use FormControl with a single element.
Featured Images: pexels.com

