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

              
                <!-- 
- Ref: https://gomakethings.com/more-html-less-javascript/ 
- Note: this sol’n requires a server-side (PHP, or Ruby, or Node etc) script endpoint for processing the submitted form data
- Why do we even need JS here? I guess because this is a thing intended for portability and you’ve made the decision that you want error and success messaging to be “white-labelled” on the consuming website rather than user being taken to a separate website, and you don’t know the context’s stack so you’ll use JS to handle the messaging, which then means you need to use JS to orchestrate everything.
- However we don’t need a JS library for this. It’s a pretty straightforward and lightweight combo of DOM manipulation plus fetch(). 
-->

<div class="container">
  <div role="status"></div>
  <form action="/path/to/an/endpoint.php">
    <label for="email">Enter your email</label>
    <input type="email" id="email" name="email">
    <button>Subscribe</button>
  </form>
</div>
              
            
!

CSS

              
                label {
  display: block;
  font-weight: bold;
}

              
            
!

JS

              
                // Get the form and error message elements
let fc = document.querySelector(".container");
let status = fc.querySelector('[role="status"]');
let form = document.querySelector("form");

// Handle submit events
function submitHandler(event) {
  // Stop the form from reloading the page
  event.preventDefault();

  // Validate the email field
  if (!form.email.value) {
    status.textContent = "Please include a valid email address.";
  }

  // Submit the form
  fetch(form.action, {
    method: "POST",
    body: JSON.stringify({ email: form.email.value }),
    headers: {
      Accept: "application/json"
    }
  })
    .then(function (response) {
      return response.json();
    })
    .then(function (data) {
      announce.textContent = data.msg;
    })
    .catch(function (error) {
      announce.textContent = "Something went wrong. Please try again.";
    });
}

// Listen for submit events
form.addEventListener("submit", submitHandler);

              
            
!
999px

Console