Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


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


                #card {
  font-family: Arial;
  font-size: 1rem;
  padding: 20px;
  border: 1px solid #ddd;

#buttons {
  padding: 10px 0px;

button {
  margin-right: 10px;

#loader {
  background-color: #ddf;
  padding: 5px;
  border-radius: 5px;
  color: #008;

#title {
  background-color: #333;
  color: #fff;
  padding: 5px;

#empty {
  background-color: #ffd;
  padding: 10px;
  color: #880;

#error {
  background-color: #fdd;
  padding: 10px;
  color: #800;


                const Card = ({ children }) => <div id="card">{children}</div>
const Title = ({ children }) => <div id="title"><h2>{children}</h2></div>
const Loader = ({ children }) => <div id="loader">{children}</div>
const Error = ({ children }) => <div id="error">{children}</div>
const Empty = ({ children }) => <div id="empty">{children}</div>

const App = () => {
  // initial state for loading
  const [dataStatus, setDataStatus] = React.useState("Loading")
  const [person, setPerson] = React.useState()

  // fake out api calls
  // setDataStatus("Loading") when waiting for the API
  const setLoading = () => { 
  // setDataStatus("Loaded") when successful with data
  const setLoaded = () => { 
    setPerson({ name: "Luke Skywalker" })
  // setDataStatus("Empty") when successful with no data
  const setEmpty = () => { 
  // setDataStatus("Error") if an error occurs
  const setError = () => { 

// now manage the state of the component
return (
    { dataStatus === "Loaded" &&
    { dataStatus === "Loading" &&
    { dataStatus === "Error" &&
      <Error>Sorry, we had an oopsie...</Error>
    { dataStatus === "Empty" &&
      <Empty>Looks like we're missing something...</Empty>
    <div id="buttons">
      <button onClick={setLoaded}>Set to Loaded</button>
      <button onClick={setEmpty}>Set to Empty</button>
      <button onClick={setError}>Set to Error</button>
      <button onClick={setLoading}>Set to Loading</button>
      Current State: {dataStatus}

ReactDOM.render(<App />, document.getElementById('root'))