Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <div class="form-item">
  <label class="form-item__label" for="select">Required select with fake placeholder</label>
  <div class="select-wrap">
    <select id="select" class="form-item__element form-item__element--select" required>
      <option disabled selected value="">Please select value</option>
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
    </select>
  </div>
</div>

<div class="form-item">
  <label class="form-item__label" for="select">How old are you?</label>
  <div class="select-wrap">
    <select id="select" class="form-item__element form-item__element--select">
      <option selected value="">Prefer not to say</option>
      <option value="1">under 18</option>
      <option value="2">over 18</option>
    </select>
  </div>
</div>

<div class="form-item">
  <label class="form-item__label" for="input">Input with placeholder</label>
  <input id="input" placeholder="Please enter value" class="form-item__element">
</div>

<div class="info">
  <h2>About this pen</h2>
  <p>To avoid the need for JavaScript we can avoid using a placeholder in optional select fields altogether by providing a neutral default option.</p>
  <p>You can read more about this pen in the following article:<br><a href="https://markus.oberlehner.net/blog/faking-a-placeholder-in-a-html-select-form-field/">Faking a Placeholder in a HTML Select Form Field</a></p>
  <p>JavaScript fallback solution:<br><a href="https://codepen.io/moberlehner/pen/YQBQNj">Fake Select Placeholder with (CSS + JavaScript Fallback)</a></p>
</div>
              
            
!

CSS

              
                $default-color: #444;

.form-item {
  &:not(:first-child) {
    margin-top: 1em;
  }
  
  > :not(:first-child) {
    margin-top: 0.25em;
  }
}

.form-item__label {
  display: block;
}

.form-item__element {
  display: inline-block;
  padding: 0.5em;
  vertical-align: middle;
  background: #fff;
  border-radius: 4px;
  border: 1px solid gray;
}

.form-item__element--select {
  appearance: none;
  padding-right: 2em;
  
  // The select element is set to required
  // as long as the selected options value
  // is empty the element is not valid.
  &:invalid {
    color: gray;
  }
  
  // Styling for browsers which do support
  // styling select option elements directly
  [disabled] {
    color: gray;
  }
  
  option {
    color: $default-color;
  }
}

// Quick and dirty ugly caret replacement.
.select-wrap {
  &::after {
    margin-left: -2em;
    font-size: 0.75em;
    pointer-events: none;
    content: '▼';
  }
}

.info {
  max-width: 42em;
  
  p {
    line-height: 1.5;
  }
}

body {
  padding: 1em;
  color: $default-color;
}

* {
  box-sizing: border-box;
}

              
            
!

JS

              
                
              
            
!
999px

Console