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

              
                <div id="root"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Courgette&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');

body {
  font-family: 'Open Sans', sans-serif;
  color: slategrey;
  margin: 0;
  background: whitesmoke;
}

header {
  width: 100%;
  padding: 1rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: gainsboro;
}

#logo {
  font-family: 'Courgette', serif;
  font-size: 2rem;
  margin: 0.5rem;
}

nav ul {
  width: 12.3rem;
  list-style: none;
}

nav ul li {
  display: inline;
  margin-right: 0.5rem;
}

nav ul li a {
  color: slategrey;
  text-decoration: none;
}

nav ul li a:hover {
  color: steelblue;
  transition: 200ms ease-in;
}

main {
  width: 100%;
  display: flex;
  justify-content: center;
}

form {
  width: 70%;
  margin-top: 2rem;
  padding: 0 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 0.1rem solid gainsboro;
  border-radius: 1rem;
}

#contact-info {
  width: 90%;
  display: flex;
  justify-content: space-between;
}

#contact-info input {
  width: 49%;
}

input {
  width: 90%;
  height: 2rem;
  padding-left: 0.5rem;
  margin-bottom: 1rem;
  border: 0.1rem solid gainsboro;
  border-radius: 0.3rem;
  box-sizing: border-box;
}

textarea {
  width: 90%;
  height: 10rem;
  resize: none;
  margin-bottom: 2rem;
  border: 0.1rem solid gainsboro;
  border-radius: 0.3rem;
  box-sizing: border-box;
}

button {
  color: white;
  width: 6rem;
  height: 3rem;
  background: darkseagreen;
  border: none;
  border-radius: 0.3rem;
}

button:hover {
  border: 0.1rem solid steelblue;
  cursor: pointer;
}

footer {
  font-size: 0.9rem;
  text-align: center;
  width: 100%;
  position: fixed;
  bottom: 0;
  padding: 0.5rem;
  background: gainsboro;
}

@media(max-width: 767px) {
  form {
    width: 90%;
  }
  
  #contact-info {
    flex-direction: column;
  }
  
  #contact-info input {
    width: 100%;
  }
  
  footer {
    display: none;
  }
}
              
            
!

JS

              
                function Header() {
  return (
    <header>
      <div id='logo'>Lorem ipsum</div>
      <nav>
        <ul>
          <li><a href='#'>Shop</a></li>
          <li><a href='#'>About</a></li>
          <li><a href='#'>Contact</a></li>
        </ul>
      </nav>  
    </header>
  );
}

function ContactForm() {
  
  const validateEmail = (e) => {
    if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.target.value) === false) {
      e.target.style.borderColor = 'red';
    } else {
      e.target.style.borderColor = 'gainsboro';
    }
  }
  
  const checkIfEmpty = (e) => {
    if (e.target.value.length <= 0) {
      e.target.style.borderColor = 'red';
    } else {
      e.target.style.borderColor = 'gainsboro';
    }
  }
  
  const handleSubmit = (e) => {
    
    const name = document.getElementById('name'),
          email = document.getElementById('email'),
          subject = document.getElementById('subject'),
          message = document.getElementById('message');
    
    if (name.value === '') {
      e.preventDefault();
      alert('All fields must be filled out before submitting.');
    } else if (email.value === '') {
      e.preventDefault();
      alert('All fields must be filled out before submitting.');
    } else if (subject.value === '') {
      e.preventDefault();
      alert('All fields must be filled out before submitting.');
    } else if (message.value === '') {
      e.preventDefault();
      alert('All fields must be filled out before submitting.');
    } else {
      e.preventDefault();
      alert(`Thank you ${name.value}, we will be in touch with you shortly.`);
      [name.value, email.value, subject.value, message.value] = ['','','',''];
    }
  }
  
  return (
    <main>
      <form id='contact'>
        <h2>Get in touch with us!</h2>
        <div id='contact-info'>
          <input 
            onChange={checkIfEmpty}
            type='text' 
            id='name' 
            placeholder='Name'
          />
          <input 
            onChange={validateEmail}
            type='text' 
            id='email' 
            placeholder='Email'
          />
        </div>  
        <input 
          onChange={checkIfEmpty}
          type='text' 
          id='subject' 
          placeholder='Subject'
        />
        <textarea 
          onChange={checkIfEmpty}
          id='message'
        >
        </textarea>
        <button 
          onClick={handleSubmit}
          type='submit' 
          form='contact' 
          value='submit'
        >
          Submit
        </button>
      </form>
    </main>  
  );
}

function Footer() {
  return (
    <footer>*This is a fake contact page assembled with React.</footer>
  );
}

function App() {
  return (
    <div>
      <Header />
      <ContactForm />
      <Footer />
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));
              
            
!
999px

Console