Lesson 19 +10 XP

Selects, Textareas, and More

More form widgets: dropdowns, big text boxes, and progress bars.

select: a dropdown

<select> makes a dropdown menu. <option> is one choice. <optgroup> groups choices with a label.

Code

html
<select name="country">
  <option value="">Choose a country</option>
  <optgroup label="Europe">
    <option value="fr">France</option>
    <option value="de">Germany</option>
  </optgroup>
  <optgroup label="Asia">
    <option value="jp">Japan</option>
  </optgroup>
</select>
  • selected: marks the default choice.
  • multiple: lets you pick several options.
Code

html
<select name="colors" multiple>
  <option>Red</option>
  <option>Blue</option>
</select>

textarea: a big text box

&lt;textarea&gt; is for long text, like a comment box. It has no type, and its text goes between the tags.

Code

html
<textarea name="message" rows="5" cols="40">
Type your message here.
</textarea>
  • rows: how many lines tall.
  • cols: how wide.
  • maxlength: the most characters allowed.

datalist: suggestions while typing

&lt;datalist&gt; gives an input a dropdown of suggestions. Link them with the input's list attribute.

Code

html
<input type="text" name="browser" list="browsers">
<datalist id="browsers">
  <option value="Chrome">
  <option value="Firefox">
  <option value="Edge">
</datalist>

output: showing a result

&lt;output&gt; displays the result of a calculation (often filled by JavaScript).

Code

html
<output name="result">0</output>

progress: a loading bar

&lt;progress&gt; shows how far something is. max is the total, value is how much is done.

Code

html
<progress max="100" value="70">70%</progress>

meter: a gauge

&lt;meter&gt; shows a measurement, like a battery level or a score.

Code

html
<meter min="0" max="100" value="80">80%</meter>

TL;DR

  • &lt;select&gt; + &lt;option&gt; = dropdown; &lt;optgroup&gt; groups choices.
  • &lt;textarea&gt; = big text box with rows, cols, maxlength.
  • &lt;datalist&gt; = autocomplete suggestions for an input.
  • &lt;output&gt; = result display.
  • &lt;progress&gt; = loading bar, &lt;meter&gt; = gauge.