menu

html - 3 Topics

HTML5 APIs

DEEP DIVE INTO

html

Topic:html textarea

menu

The <textarea> element in HTML is used to create a multi-line text input field within a web form. It allows users to input multiple lines of text, making it suitable for scenarios where users need to provide longer text entries, such as comments, descriptions, or messages. Here's how to use the <textarea> element and some examples of its usage:

html<textarea name="inputName" rows="4" cols="40">Default text goes here</textarea>

Attributes:

  1. name: Specifies the name for the text area, which is used when the form is submitted to identify the field's data.

  2. rows: Specifies the number of visible text lines in the text area. This attribute determines the initial height of the text area.

  3. cols: Specifies the number of visible characters per line. This attribute determines the initial width of the text area.

Example:

html<form>
  <label for="comments">Enter your comments:</label><br>
  <textarea id="comments" name="userComments" rows="6" cols="40">Your comments here.</textarea><br>
  <input type="submit" value="Submit">
</form>

In this example, we create a simple form with a text area where users can enter comments. The rows and cols attributes set the initial size of the text area.

Common Use Cases:

  1. Comment Forms: Text areas are commonly used in comment forms on websites, allowing users to leave longer comments or feedback.

  2. Contact Forms: When building a contact form, a text area can be used for the message or inquiry field.

  3. Message Boxes: In messaging applications or chat interfaces, a text area can be used for composing and sending messages.

  4. Text Editing: Some web applications use text areas for text editing, allowing users to input and edit longer pieces of content.

  5. User Profiles: Text areas are used in user profile forms for users to provide detailed descriptions or bios.

Styling with CSS:

The appearance of a <textarea> element can be customized using CSS. You can adjust its font, color, size, borders, and other visual properties to match your website's design.

Here's an example of how you might use CSS to style a <textarea> element:

html<textarea id="comments" name="userComments" rows="6" cols="40" class="custom-textarea">Your comments here.</textarea>
css.custom-textarea {
  font-family: Arial, sans-serif;
  font-size: 14px;
  color: #333;
  border: 1px solid #ccc;
  padding: 5px;
  resize: none; /* Prevent resizing by the user */
}

In this example, we add a class "custom-textarea" to the <textarea> and apply CSS rules to control its appearance, including font, size, color, border, padding, and preventing user resizing.

The <textarea> element is a valuable part of web forms, allowing users to provide longer text inputs. It is versatile and can be customized to fit various design and functionality requirements in web applications.

1280 x 720 px