Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>There can be only one</h1>
<div>
<form action="" method="get">
  
  <h2>Basic <code>select</code></h2>
<p>
  <label for="fruit">What’s your favorite fruit?</label>
  <select name="fruit" id="fruit">
    <option>Apple</option>
    <option>Orange</option>
  </select>
</p>

<h2>Different value</h2>
<p>
  <label for="location">Where are you?</label>
  <select name="location" id="location">
    <option value="US">United States</option>
    <option value="non-US">Outside the United States</option>
  </select>
</p>

<h2>Empty default choice</h2>
<p>
  <label for="fruit_2">What’s your favorite fruit?</label>
  <select name="fruit_2" id="fruit_2">
    <option value="">-- Choose One --</option>
    <option>Apple</option>
    <option>Orange</option>
  </select>
</p>
  
<h2>Pre-selected option</h2>
<p>
  <label for="fruit_3">What’s your favorite fruit?</label>
  <select name="fruit_3" id="fruit_3">
    <option value="">-- Choose One --</option>
    <option>Apple</option>
    <option selected>Orange</option>
  </select>
</p>
  
<h2>Grouped options</h2>
<p>
  <label for="fruit_4">What’s your favorite fruit?</label>
  <select name="fruit_4" id="fruit_4">
    <optgroup label="Pome">
      <option>Apple</option>
      <option>Pear</option>
    </optgroup>
    <optgroup label="Citrus">
      <option>Orange</option>
      <option>Tangerine</option> 
    </optgroup>
  </select>
</p>
  
<h2>Required field</h2>
  <p>
    <label for="fruit_5">What’s your favorite fruit?</label>
  <select name="fruit_5" id="fruit_5" required aria-required="true">
    <option value="">-- Choose One --</option>
    <option>Apple</option>
    <option>Orange</option>
  </select>
</p>
  
<h2>Unsetting the appearance</h2>
  <p>
    <label for="fruit_6">What’s your favorite fruit?</label>
  <select name="fruit_6" id="fruit_6">
    <option value="">-- Choose One --</option>
    <option>Apple</option>
    <option>Orange</option>
  </select>
</p>
  
<h2>Custom CSS</h2>
  <p>
    <label for="fruit_7">What’s your favorite fruit?</label>
  <select name="fruit_7" id="fruit_7">
    <option value="">-- Choose One --</option>
    <option>Apple</option>
    <option>Orange</option>
  </select>
</p>
  
  <h2><code>select</code> with "other"</h2>
  <p>
    <label for="fruit_8">What’s your favorite fruit?</label>
<select name="fruit_8" id="fruit_8">
  <option value="">-- Choose One --</option>
  <option>Apple</option>
  <option>Orange</option>
  <option>Other</option>
</select>
<label for="fruit_8_other">If you chose "other," what <em>is</em> your favorite fruit?</label>
<input id="fruit_8_other" name="fruit_8">
  </p>

<h2>Radio field</h2>
  <fieldset>
  <legend>What’s your favorite fruit?</legend>
  <label>
    <input type="radio" name="fruit_9"
value="Apple">
    Apple
  </label>
  <label>
    <input type="radio" name="fruit_9"
value="Orange">
    Orange
  </label>
</fieldset>
  
<h2>Required radio</h2>
  <fieldset>
  <legend>Required fruit</legend>
  <label>
    <input type="radio" name="fruit_10" value="Apple" required>
    Apple
  </label>
  <label>
    <input type="radio" name="fruit_10" value="Orange" required>
    Orange
  </label>
</fieldset>
  
<h2>Radio with other</h2>
<fieldset>
  <legend>What’s your favorite fruit?</legend>
  <label>
    <input type="radio" name="fruit_11" value="Apple">
    Apple
  </label>
  <label>
    <input type="radio" name="fruit_11" value="Orange" checked>
    Orange
  </label>
  <label>
    <input type="radio" name="fruit_11" value="Other">
    Other
  </label>
  <p>
    <label for="fruit_11-other">If you chose "other," what <em>is</em> your favorite fruit?</label>
    <input id="fruit_11-other" name="fruit_11">
  </p>
</fieldset>
  
  <h2><code>datalist</code></h2>
  <p>
    <label for="fruit_12">What’s your favorite fruit?</label>
<input name="fruit_12" id="fruit_12" list="fruit_12-options">
<datalist id="fruit_12-options">
  <option>Apple</option>
  <option>Orange</option>
</datalist>
  </p>
  
  <button type="submit">See what you get</button>
</form>

<output></output>
</div>
</main>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 1em;
}

div {
  display: grid;
}
@media (min-width: 60em) {
  div {
    grid-template-columns: 1fr 1fr;
  }
}

p {
  margin-bottom: 5em;
}

label {
  font-weight: bold;
  display: block;
  margin: .5em 0 .25em;
}

#fruit_6 {
  appearance: none;
}
#fruit_7 {
  background: green;
  color: white;
  font-family: "Comic Sans MS", "Comic Sans", cursive;
  font-size: 2rem;
}

fieldset {
  border: 0;
  margin: 0 0 5em;
  padding: 0;
}
legend {
  font-weight: bold;
}
label:has(input) {
  font-weight: normal;
}

output {
  display: block;
  border: 1px solid;
  background: #ebebeb;
  margin: 2em 0;
  padding: 1em;
  white-space: pre-wrap;
  height: 300px;
  overflow: scroll;
}
              
            
!

JS

              
                var $output = document.querySelector("output"),
     $form = document.forms[0];

$form.addEventListener('submit',function(e){
  e.preventDefault();
  show("-- New form submission --");
  var form_data = new FormData($form);
  var data = [...form_data.entries()]
  var output = {};
  data.forEach(item => {
    output[item[0]] = item[1];
  });
  for ( key in output ) {
    show(`${key}: ${output[key]}`);
  }
  show("\r\n");
}, false);

function show(str) {
  $output.innerText += str + "\r\n";
}
              
            
!
999px

Console