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

              
                <div class="container form">
  <h1>Wikipedia</h1>
  <form onsubmit="wikiSearch(event)">
    <input id="search" type="text" name="search"><button type="submit" >Search</button>
  </form>
  <br>
  <a target="_blank" href="https://en.wikipedia.org/wiki/Special:Random">Random Article</a>
  
</div>
<div class="container">
  <div id="results"></div>
</div>

              
            
!

CSS

              
                .form {
  text-align: center;
  margin: 0 auto;
  margin-top: 10vh;
}
form {
  margin-top: 25px;
  margin-bottom: 5px;
}
button {
  border-radius: 0 30px 30px 0;
  border: none;
  font-size: 17px;
}
input {
  border-radius: 30px 0 0 30px;
}
input:focus {
  outline: none;
  box-shadow: 0 0 2pt 1pt grey;
}
button:focus {
  border: none;
  outline: none;
  box-shadow: 0 0 2pt 1pt grey;
}

              
            
!

JS

              
                var wikiData;
var page = "//en.wikipedia.org/?curid=";

//This function fires when the form is submited. Either by the click of the 'search' button or by pressing the enter button.
function wikiSearch(event) {
  event.preventDefault(); //prevents query from clearing too early
  var query = document.getElementById("search").value;

  //URL information for API call
  var api =
    "//en.wikipedia.org/w/api.php?origin=*&format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=";
  //API get request to wikipedia
  $.getJSON(api + query).then(data => {
    wikiData = data.query.pages;
    draw(); //Calls the draw function once the data is retrived
  });
}

//The draw method cycles through the JSON data recieved from wikipedia and prints it to the screen.
function draw() {
  var template = "";
  Object.keys(wikiData).forEach(function(key) {
    template += `
      <div class="row">
        <div class="col-xs-12">
              <h3><a href=${page + wikiData[key].pageid} target="_blank">${
      wikiData[key].title
    }</a></h3>
              <p>${wikiData[key].extract}</p>
        </div>
      </div>
    `;
  });
  document.getElementById("results").innerHTML = template; //Set results section equal to the template
  document.getElementById("search").value = ""; // reset the search form to empty string
}

              
            
!
999px

Console