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

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

              
                header.push-down
  h1 Wikipedia Viewer

.random: a(href="http://en.wikipedia.org/wiki/Special:Random") Random Article

.search
  .handle
  form
    input
      
.results

script#results-template(type="text/x-handlebars-template")
  | {{#each results}}
  a(href="{{canonicalurl}}")
    .result
      .title {{title}}
      .extract {{{extract}}}
  | {{/each}}

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto)

$text-color: #ddd
$bg-color: #345

body
  font-family: 'Roboto', sans-serif
  text-align: center
  background-color: $bg-color
  color: $text-color

a
  color: #aaf

header
  transition: margin 0.4s

.push-down
  margin-top: 5em

.random, .search, .results
  margin: 2em

.result
  margin: 1em
  padding: 0.5em
  .title
    margin-bottom: 0.5em

.random
  a
    text-decoration: none

.search
  position: relative
  label
    display: block
  input
    position: relative
    z-index: 1
    background-color: mix(white, $bg-color, 20%)
    color: $text-color
    font-size: 1.2em
    width: 1.4em
    height: 1.4em
    padding: 1em
    border-radius: 2em
    border: 3px solid $text-color
    transition: width 0.4s

.search .handle
  position: absolute
  bottom: 0
  left: 50%
  width: 3em
  height: 0
  border: 3px solid $text-color
  transform: rotate(45deg)
  transition: all 0.4s

.result
  text-align: left
  background-color: white
  color: #333
  border-left:
    color: $bg-color
    style: solid
    width: 3px
  .title
    font-size: 1.5em

.results a
  text-decoration: none
  .result:hover
    border-left:
      color: orange
      style: solid
      width: 3px

              
            
!

JS

              
                var results_template = Handlebars.compile($('#results-template').html());

$('.search form').submit(function(event) {
  event.preventDefault();
  var search_query = $('.search input').val();
  $.ajax('https://en.wikipedia.org/w/api.php', {
    dataType: 'jsonp',
    success: function(data) {
      $('.results').hide();
      $('.results').html(results_template({results: data.query.pages}));
      $('header').removeClass('push-down');
      $('.results').fadeIn();
    },
    data: {
      action: 'query',
      generator: 'search',
      gsrsearch: search_query,
      gsrlimit: 10,
      prop: 'info|extracts',
      inprop: 'url',
      exintro: true,
      exlimit: 10,
      format: 'json',
      utf8: ''
    }
  });
});

$('.search input').focus(function() {
  $(this).css('width', '20em');
  $('.search .handle').css({width: 0, opacity: 0});
});

$('.search input').blur(function() {
  if ($(this).val().length === 0) {
    $(this).css('width', '');
    $('.search .handle').css({width: '', opacity: ''});
  }
});

              
            
!
999px

Console