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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <form>
  <div class="row">
    <input type="search" name="pokemon" placeholder="pokemon" aria-label="Search for a pokemon by name" value="pikachu" required>
    <button type="submit" aria-label="search">🔍</button>
  </div>
  <output>
    <pre>
      <!-- Where our pokemon data will go -->
    </pre>
  </output>
</form>
              
            
!

CSS

              
                body {
  font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  color: hsl(200, 20%, 20%);
  background-color: hsl(200, 10%, 98%);
}

form {
  max-width: 22rem;
  margin: 0 auto;
  padding: 2rem;
}

input,
button {
  display: block;
  background: #fff;
  border: 0;
  padding: 0.5rem;
  font: inherit;
  color: inherit;
}

input { 
  flex: 1;
}

button {
  padding: 0.5rem 1rem;
  background-color: hsl(200, 10%, 94%);
}

.row {
  display: flex;
  box-shadow: 0 1px 4px hsla(200, 10%, 40%, 0.5);
  border-radius: 0.25rem;
  overflow: hidden;
}
              
            
!

JS

              
                // our GraphQL query accepts a $name variable and uses it to query for a specific pokemon
// it asks for the pokemon's  ID, name and weight to be returned
const query = `
query Pikachu($name: String!) {
  pokemon(name: $name) {
    id
    name
    weight
  }
}
`;

function fetchPokemon(name) {
  // send a POST request with our query as a JSON body to our API
  return fetch("https://pokemon-gql.now.sh/api", {
    method: "POST",
    headers: { "content-type": "application/json" },
    // we send the query and variables separately—the GraphQL server will inject the variables into the query
    body: JSON.stringify({ query, variables: { name } })
  })
    .then(response => {
      // if we get a bad response we error
      if (!response.ok) throw new Error("Request failed");
      // we know this API returns JSON
      return response.json();
    })
}

const output = document.querySelector("output > pre");

function update(json) {
  if (!json || !json.data || !json.data.pokemon) {
    output.textContent = "Pokemon not found";
  } else {
    // shove the response JSON into a <pre> so we can see it
    // the third argument to JSON.stringify is the indentation size (this causes it to pretty print)
    output.textContent = JSON.stringify(json, null, 2);
  }
}

function search(event) {
  // stop the default HTML form submit that refreshes the page
  event.preventDefault();
  // grab the name the user entered from the input with `name="pokemon"`
  const name = event.target.elements.pokemon.value;
  fetchPokemon(name).then(update)
}

const form = document.querySelector("form")
form.addEventListener("submit", search);

// run the fetch once so the page starts off with a pokemon visible
fetchPokemon("pikachu").then(update);
              
            
!
999px

Console