Using the <text> Element

Elements of type text create basic single-line text fields. The Try It example in this section will help you make your first text element. Text elements also have many attributes that can be helpful such as list, maxLength, minLength, size, and a few more. The section also introduces client-side validation of text fields which will be covered in detail later.

Value

The value attribute is a string that contains the current value of the text entered into the text field. You can retrieve this using the HTMLInputElement value property in JavaScript.

let theText = myTextInput.value;

If no validation constraints are in place for the input (see Validation for more details), the value may be an empty string ("").