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 class="main-container" data-ng-style="whatTheFontController.currentStyle" id="WhatTheFont" data-ng-controller="WhatTheFontController as whatTheFontController">
    <span class="number" data-ng-bind="whatTheFontController.currentPage">
            1
        </span>
    <div class="card-main">
      <div class="card-main-inner">
        <h1 class="card-main-title">What The Font?!</h1>
        <p class="card-main-question">What font do you think I am?</p>
        <div class="card-main-input-container">
          <div>
            <input id="searchInput" class="card-main-input" type="text" placeholder="Start typing a font here..." name="search" data-ng-model="whatTheFontController.query" autocomplete aa-datasets="getDatasets()" aa-options="{hint: false}">
          </div>
          <div class="card-main-input-icon ng-cloak" data-ng-if="whatTheFontController.query != '' && whatTheFontController.query.toLowerCase() != whatTheFontController.currentFont.toLowerCase()">
            <svg viewBox="0 0 1024 1024"><path d="M486.4 1024c-129.922 0-252.067-50.594-343.936-142.464s-142.464-214.014-142.464-343.936c0-129.923 50.595-252.067 142.464-343.936s214.013-142.464 343.936-142.464c129.922 0 252.067 50.595 343.936 142.464s142.464 214.014 142.464 343.936-50.594 252.067-142.464 343.936c-91.869 91.87-214.014 142.464-343.936 142.464zM486.4 102.4c-239.97 0-435.2 195.23-435.2 435.2s195.23 435.2 435.2 435.2 435.2-195.23 435.2-435.2-195.23-435.2-435.2-435.2z M733.808 723.266l-208.874-185.666 208.874-185.667c10.566-9.394 11.518-25.574 2.126-36.141-9.394-10.566-25.574-11.522-36.142-2.126l-213.392 189.682-213.392-189.68c-10.568-9.392-26.749-8.44-36.141 2.126-9.394 10.566-8.442 26.749 2.126 36.141l208.874 185.666-208.875 185.666c-10.566 9.394-11.518 25.574-2.126 36.142 5.059 5.691 12.085 8.592 19.142 8.592 6.048 0 12.122-2.131 16.998-6.466l213.394-189.683 213.392 189.683c4.878 4.334 10.949 6.466 16.998 6.466 7.058 0 14.086-2.902 19.144-8.592 9.392-10.568 8.44-26.749-2.126-36.142z"></path></svg>
          </div>
          <div class="card-main-input-icon correct ng-cloak" data-ng-if="whatTheFontController.query != '' && whatTheFontController.query.toLowerCase() === whatTheFontController.currentFont.toLowerCase()">
            <svg viewBox="0 0 1024 1024"><path d="M486.4 1024c-129.922 0-252.067-50.594-343.936-142.464s-142.464-214.014-142.464-343.936c0-129.923 50.595-252.067 142.464-343.936s214.013-142.464 343.936-142.464c129.922 0 252.067 50.595 343.936 142.464s142.464 214.014 142.464 343.936-50.594 252.067-142.464 343.936c-91.869 91.87-214.014 142.464-343.936 142.464zM486.4 102.4c-239.97 0-435.2 195.23-435.2 435.2s195.23 435.2 435.2 435.2 435.2-195.23 435.2-435.2-195.23-435.2-435.2-435.2z M384 742.4c-6.552 0-13.102-2.499-18.102-7.499l-153.6-153.6c-9.997-9.997-9.997-26.206 0-36.203 9.998-9.997 26.206-9.997 36.205 0l135.498 135.498 340.299-340.298c9.997-9.997 26.206-9.997 36.203 0 9.998 9.998 9.998 26.206 0 36.205l-358.4 358.4c-5 4.998-11.55 7.498-18.102 7.498z"></path></svg>
          </div>
        </div>
        <div class="card-main-link" data-ng-click="whatTheFontController.dataStore.nextFont()" data-ng-bind="whatTheFontController.query.toLowerCase() === whatTheFontController.currentFont.toLowerCase() ? 'Next': 'Skip'">
          Skip
        </div>
      </div>
    </div>
    <div class="card-secondary">

    </div>
  </div>
              
            
!

CSS

              
                *,
*:before,
*:after {
    box-sizing: inherit;
}

@mixin media($breakpoint) {
    @media (max-width: $breakpoint) {
        @content;
    }
}

@mixin media-height($breakpoint) {
    @media (max-height: $breakpoint) {
        @content;
    }
}

// ------------- VARIABLES ------------- //
$offset-size: 4em;
$outer-offset-size: 7em;
// ------------- GENERAL ------------- //
.ng-cloak {
    opacity: 0;
}

body {
    color: #5b5b5b;
    min-height: 100vh;
    background-size: cover;
    background-position: center center;
    background-image: linear-gradient(to bottom, rgba(31, 34, 48, 0.9) 0%, rgba(67, 70, 93, 0.9) 100%), url(http://emilyhayman.com/codepens/pexels-photo-101550.jpg);
    display: flex;
    cursor: default;
    justify-content: center;
  align-items: center;
    ::selection {
        background-color: rgba(46, 49, 52, .7);
        color: #f5f5f1;
    }
    ::-moz-selection {
        background-color: rgba(46, 49, 52, .7);
        color: #f5f5f1;
    }
}

.number {
    position: absolute;
    font-size: 110vh;
    z-index: 20;
    line-height: 0;
    top: 50%;
    color: rgba(0, 0, 0, .05);
    font-family: sans-serif;
    right: 0;
    pointer-events: none;
    letter-spacing: -.18em;
    @include media(730px) {
        font-size: 130vh;
        right: -.03em;
    }
}

.main-container {
    position: relative;
    overflow: hidden;
    margin: 4.5em;
    flex-grow: 1;
    padding-bottom: $offset-size;
    padding-right: $offset-size;
    font-family: 'Montserrat';
    max-width: 1000px;
    @include media(730px) {
        margin: 1em;
        padding-right: 1em;
        padding-bottom: 1em;
    }
}

.card-main {
    background-color: #fff;
    height: 100%;
    z-index: 10;
    position: relative;
    box-shadow: 12px 12px 15px hsla(0, 0%, 0%, 0.03);
    padding: 6em 3.5em;
    display: flex;
    justify-content: center;
    flex-direction: column;
    @include media(730px) {
        padding: 2em;
    }
    &-title {
        color: #3b4046;
        line-height: 1;
        font-size: 7.2rem;
        max-width: 700px;
        font-weight: bold;
        margin-bottom: .5em;
        @include media(730px) {
            font-size: 4.5rem;
        }
    }
    &-question {
        line-height: 1.5;
        font-size: 1.1rem;
        margin-bottom: 1.6em;
    }
    &-input {
        border: 0;
        border-bottom: 2px solid #ddd;
        line-height: 1.5;
        font-size: .9rem;
        padding: 0 0 .5em;
        width: 100%;
        transition: .2s;
        color: #3b4046;
        font-family: inherit;
        &::-webkit-input-placeholder {
            color: #d8d8d8;
        }
        &::-moz-placeholder {
            color: #d8d8d8;
            opacity: 1;
        }
        &:-ms-input-placeholder {
            color: #d8d8d8;
        }
        &:focus {
            outline: 0;
            border-bottom-color: rgba(49, 198, 178, 0.9);
        }
        &-container {
            display: flex;
            margin-bottom: 15px;
            > div:first-child {
                max-width: 700px;
                flex-grow: 1;
            }
        }
        &-icon {
            width: 30px;
            height: 30px;
            margin-left: 1em;
            transition: .18s ease-in;
            &.correct {
                svg {
                    fill: rgba(49, 198, 178, 0.9);
                }
            }
            svg {
                fill: #ff7d7d;
            }
        }
    }
    &-link {
        position: absolute;
        right: 2em;
        bottom: 2em;
        text-transform: uppercase;
        font-size: 1.2rem;
        letter-spacing: .1rem;
        cursor: pointer;
        transition: .18s ease-in;
        user-select: none;
        &:hover {
            color: rgba(49, 198, 178, 0.9);
        }
    }
}

.card-secondary {
    background-image: linear-gradient(to top, #2ad5d0 0%, rgba(49, 198, 178, 0.9) 4em);
    left: $offset-size;
    top: $offset-size;
    position: absolute;
    bottom: 0;
    right: 0;
    @include media(730px) {
        left: 1em;
        top: 1em;
    }
}

.algolia-autocomplete {
    width: 100%;
}

.aa-dropdown-menu {
    background-color: rgb(255, 255, 255);
    width: 100%;
    max-width: 700px;
    padding: 1em;
    color: #bbb;
    border-top: 0;
    box-shadow: 3px 3px 25px rgba(8, 35, 32, 0.08);
    top: calc(100% + 2px)!important;
    .aa-suggestion {
        font-size: .9rem;
        transition: .18s ease;
        em {
            color: #3b4046;
        }
        + .aa-suggestion {
            margin-top: 1em;
        }
        &.aa-cursor {
            color: #32b9a9;
            cursor: pointer;
        }
    }
}

// ------------- RESET ------------- //

/* https://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}


/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
    display: block;
}

body {
    line-height: 1;
}

ol,
ul {
    list-style: none;
}

blockquote,
q {
    quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
    content: '';
    content: none;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

html {
    box-sizing: border-box;
}
              
            
!

JS

              
                class DataStore {

  static get $inject() {
    return ['algolia', 'APP_ID', 'API_KEY', 'INDEX', 'FONTS_NUMBER', '$rootScope'];
  }

  constructor(algolia, APP_ID, API_KEY, INDEX, FONTS_NUMBER, $rootScope) {
    this.query = "";
    this._algolia = algolia;
    this._APP_ID = APP_ID;
    this._API_KEY = API_KEY;
    this._INDEX = INDEX;
    this._FONTS_NUMBER = FONTS_NUMBER;
    this._$rootScope = $rootScope;

    this._client = algoliasearch(this._APP_ID, this._API_KEY);
    this._currentIndex = this._client.initIndex(this._INDEX);

    this._performSearch(this._FONTS_NUMBER);
    this._currentFont = "Montserrat";
    this._currentPage = 1;
    this._fontPage = 0;
  }

  get graphData() {
    return this._graphData;
  }

  get topFonts() {
    return this._topFonts;
  }

  get currentFont() {
    if (this._currentFont) {
      return this._currentFont;
    }
  }

  get success() {
    return this._success = false;
  }

  get currentPage() {
    return this._currentPage;
  }

  _performSearch() {
    this._currentIndex.search('', {
      hitsPerPage: this._FONTS_NUMBER,
      page: this._fontPage
    }).then((results) => {
      this._topFonts = this._getResults(results).filter(item => item != this._currentFont);
      this._topFonts.forEach(el => {
        var node = document.createElement("LINK");
        node.rel = "stylesheet";
        node.href = "https://fonts.googleapis.com/css?family=" + el;
        document.body.appendChild(node);
      })
    }).catch(err => this._handleFetchError(err));
  }

  _updateFonts() {
    this._currentFont = _.sample(this._topFonts);
    this._topFonts = this._topFonts.filter(item => item != this._currentFont);
  }

  _handleFetchError(err) {
    console.log(err);
  }

  _getResults(results) {
    return results.hits.map(item => item.family);
  }

  nextFont() {
    this._updateFonts();
    this._currentPage = this._currentPage + 1;
    this.query = "";
    this._$rootScope.$evalAsync();
    if (this._currentPage === (this._FONTS_NUMBER * (this._fontPage + 1))) {
      this._fontPage = this._fontPage + 1;
      this._performSearch(this._fontPage);
    }
  }

}

class WhatTheFontController {

  static get $inject() {
    return ['dataStore', '$scope', 'algolia', 'APP_ID', 'API_KEY', 'INDEX'];
  }

  constructor(dataStore, $scope, algolia, APP_ID, API_KEY, INDEX) {
    this._dataStore = dataStore;
    this._$scope = $scope;
    this._algolia = algolia;
    this._APP_ID = APP_ID;
    this._API_KEY = API_KEY;
    this._INDEX = INDEX;

    this._client = algoliasearch(this._APP_ID, this._API_KEY);
    this._currentIndex = this._client.initIndex(this._INDEX);

    this._$scope.getDatasets = function() {
      return {
        source: this._algolia.sources.hits(this._currentIndex, {
          hitsPerPage: 4
        }),
        displayKey: 'family',
        templates: {
          suggestion: function(suggestion) {
            return '<span>' +
              suggestion._highlightResult.family.value + '</span>';
          }
        }
      };
    }.bind(this);

    this._$scope.$on('autocomplete:selected', (event, suggestion, dataset) => {
      this.query = suggestion.family;
      $scope.$evalAsync();
    });
  }

  get dataStore() {
    return this._dataStore;
  }

  get query() {
    return this._dataStore.query;
  }

  set query(value) {
    this._dataStore.query = value;
  }

  get currentFont() {
    return this._dataStore.currentFont;
  }

  get currentPage() {
    return this._dataStore.currentPage;
  }

  get currentStyle() {
    return {
      'font-family': this.currentFont
    };
  }

  get topFonts() {
    return this._dataStore.topFonts;
  }

}

angular.module('WhatTheFont', ['algoliasearch', 'algolia.autocomplete'])
  .config(['$compileProvider', function($compileProvider) {
    $compileProvider.debugInfoEnabled(false);
  }])
  .constant('APP_ID', 'Q71HM8430Y')
  .constant('API_KEY', 'c6cd2c56cb11609a2f43e88f0b569a55')
  .constant('INDEX', 'google_fonts')
  .constant('FONTS_NUMBER', 10)
  .service('dataStore', DataStore)
  .controller('WhatTheFontController', WhatTheFontController);

angular.element(document).ready(function() {
  angular.bootstrap(document.getElementById("WhatTheFont"), ['WhatTheFont']);
})
              
            
!
999px

Console