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

              
                <body>
  <main>
    <h1>Labeling Form Elements</h1>
    <form class="flow">
      <!-- Labeling text inputs -->
      <fieldset class="form-field example__good">
        <legend>Labeling text inputs</legend>
        <label for="name">Name</label>
        <input type="text" id="name" />
      </fieldset>
      
      <!-- Label checkboxes -->
      <fieldset class="form-field example__good">
        <legend>Labeling checkboxes</legend>
        <input type="checkbox" id="newsletter" />
        <label for="newsletter">Subscribe to newsletter?</label>
      </fieldset>
      
      <!-- Labeling radio buttons -->
      <fieldset class="form-field example__good">
        <legend>Labeling radio buttons</legend>
        <input id="red" type="radio" name="favoritecolor" value="red">
        <label for="red">Red</label>
        
        <input id="green" type="radio" name="favoritecolor" value="green">
        <label for="green">Green</label>
        
        <input id="blue" type="radio" name="favoritecolor" value="blue">
        <label for="green">Blue</label>
      </fieldset>
      
      <!-- Labeling select boxes -->
      <fieldset class="form-field example__good">
        <legend>Labeling select boxes</legend>
        <label for="nestate">Visit a State in New England</label>
        <select id="nestate">
          <option disabled selected value>Choose a State</option>
          <option value="1">Connecticut</option>
          <option value="2">Maine</option>
          <option value="3">Massachusetts</option>
          <option value="4">New Hampshire</option>
          <option value="5">Rhode Island</option>
          <option value="6">Vermont</option>
          </select>
      </fieldset>
      
      <fieldset class="form-field example__good">
        <legend>Labeling an icon button</legend>
        <button aria-label="Close">X</button>
      </fieldset>
      
      <fieldset class="form-field example__good">
        <legend>Alternative labeling techniques</legend>
        
        <!-- Wrap a form field in a <label> tag -->
        <label>
          <span class="d-block">Phone Number</span>
          <input type="text" type="num" placeholder="(XXX)XXX-XXXX" />
        </label>
        
        <br><br>
        
        <!-- Label a text input, such as a search field, using the value of its corresponding button -->
        <input type="text" name="search" aria-labelledby="searchbtn">
        <button type="submit" id="searchbtn">Search</button>
    </form>
  </main>
</body>      
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,600");

:root {
  --space: 1.5rem;
  --radius: 0.5rem;
}

body {
  background-color: #cdcdcd;
  font-family: "Open Sans", sans-serif;
}

p,
li {
  line-height: 1.6;
}

main {
  display: grid;
  place-items: center;
  max-width: 65ch;
  margin: 2rem auto;
  background-color: #fefefe;
  border-radius: var(--radius, 0.25rem);
  padding: var(--space, 1.5rem);
  box-shadow: 15px 10px -10px rgba(0, 0, 0, 0.25);
}

img {
  max-width: 300px;
}

/* Utility Classes */
.flow > * + * {
  margin-top: var(--space, 1.5rem);
}

.d-block {
  display: block;
}

.txt-small {
  font-size: 90%;
}

.txt-light {
  color: #444444;
}

/* Examples */
form {
  width: 100%;
}

label + input[type="text"],
label + select {
  display: block;
}

input {
  padding: 0.25rem;
  border: 1px solid #999999;
  border-radius: 0.25rem;
}

.example__bad {
  border-left: 4px solid red;
}

.example__good {
  border-left: 4px solid green;
}
              
            
!

JS

              
                
              
            
!
999px

Console