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

              
                <h1>Toggling Passwords in Multiple Forms</h1>

<h2>Change Username</h2>

<p>Enter your username and password to change your username.</p>

<form>
  <p>
    <label for="username">Username</label>
    <input id="username" type="text" name="username">
  </p>

  <p>
    <label for="password">Password</label>
    <input id="password" type="password" name="password" data-password>
  </p>

  <p>
    <label for="show-password">
      <input id="show-password" type="checkbox" name="show-password" data-toggle>
      Show password
    </label>
  </p>

  <p>
    <button type="submit">Change Username</button>
  </p>
</form>

<h2>Change Password</h2>

<p>Enter your current password and new password below.</p>

<form>
  <p>
    <label for="current-password">Current Password</label>
    <input id="current-password" type="password" name="current-password" data-password>
  </p>

  <p>
    <label for="new-password">New Password</label>
    <input id="new-password" type="password" name="new-password" data-password>
  </p>

  <p>
    <label for="show-passwords">
      <input id="show-passwords" type="checkbox" name="show-passwords" data-toggle>
      Show passwords
    </label>
  </p>

  <p>
    <button type="submit">Change Passwords</button>
  </p>
</form>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  width: 88%;
  max-width: 30em;
  margin: 1em auto;
  line-height: 1.5;
  background-color: #fdfdfd;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}

label, input:not([type='checkbox']) {
  display: block;
}

input:not([type='checkbox']), button {
  border: .125em solid #999;
  border-radius: .25em;
  font: inherit;
}

input:not([type='checkbox']) {
  width: 100%;
  padding: .5em;
  background-color: #fff;
}

[type='checkbox'] {
  margin-left: 0;
}

button {
  padding: .5em 1em;
  background-color: #eee;
  transition: background-color 100ms;
}

button:hover {
  background-color: #999;
}
              
            
!

JS

              
                //
// Functions
//

/**
 * Toggle the visibility of a password field
 * based on a checkbox's current state
 * 
 * @param {HTMLInputElement} checkbox The checkbox
 * @param {HTMLInputElement} field The password field
 */
function togglePassword (checkbox, field) {
  field.type = checkbox.checked ? 'text' : 'password';
}

/**
 * Handle change events
 * @param {Event} event The Event interface
 */
function handleChange (event) {
  // If this wasn't a password toggle, just bail
  if (!event.target.matches('[data-toggle]')) return;

  // Get all password fields inside this form
  const passwords = Array.from(
    event.target.form.querySelectorAll('[data-password]')
  );

  // Toggle the password fields
  passwords.forEach(function (password) {
    togglePassword(event.target, password);
  });
}


//
// Inits & Event Listeners
//

// Handle change events
document.body.addEventListener('change', handleChange);
              
            
!
999px

Console