← Community home

How do you set initial text in a textarea?

Community › Forums › HTML Forms › How do you set initial text in a textarea?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #90

    Your textarea displays no saved text because you supplied a value attribute.

    #91

    Detailed answer

    Put initial content between the textarea tags.

    Unlike a single-line input, textarea does not use a value attribute for initial content. A placeholder supplies a hint, not a label or a saved value. Escape saved user content before rendering it so it cannot unexpectedly close the textarea element.

    Example

    <label for="bio">Project description</label><textarea id="bio" name="bio" rows="4">A small HTML project.</textarea>

    Understanding the behavior

    A textarea's initial text belongs between its tags, unlike an input's value attribute. Whitespace in that content can become part of the initial value, so indentation copied from a template may be visible in the field.

    Practical implementation notes

    Inspect both the defaultValue and the current value when debugging scripts. Updating the user's current text is different from changing the reset value that the form returns to.

    How to check it

    Move the initial text between the start and end tags, then reload the page.

    Expected result

    The initial description appears as editable content.

    Watch out: Do not confuse default text with a placeholder hint.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.