Search code examples
textareamaterialize

How can I set a default value for a Materializecss textarea element?


I have a text are and i use materialize css and i what it to have some default value but it is not showing up. I have filled the value field with default value but it is now showing up. Below is my code. Please help me here

<div class="input-field">
    <textarea id="description" name="description" class="materialize-textarea" required="" value="Default value"></textarea>
     <label for="description">A brief description of your hostel</label>
</div>

Solution

  • Because text inputs are self closing tags, we set default value using value. With textares we can either put the text inside the tags, or use placeholder:

    <textarea id="textarea1" class="materialize-textarea" data-length="120">I am default text</textarea>
    <textarea id="textarea2" class="materialize-textarea" data-length="120" placeholder="I am placeholder text"></textarea>
    

    Codepen here.