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.

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

            
              <header>
</header>
<section></section>
            
          
!

CSS

            
              /* Bootstrap 4 Reset */

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

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
  font-size: 62.5%;
}
html, body {
  height: 100%;
}

@-ms-viewport {
  width: device-width;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 1.4rem;
  font-weight: normal;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
}

[tabindex="-1"]:focus {
  outline: none !important;
}

hr {
  box-sizing: content-box;
  height: 0;
  overflow: visible;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: .5rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

abbr[title],
abbr[data-original-title] {
  text-decoration: underline;
  -webkit-text-decoration: underline dotted;
          text-decoration: underline dotted;
  cursor: help;
  border-bottom: 0;
}

address {
  margin-bottom: 1rem;
  font-style: normal;
  line-height: inherit;
}

ol,
ul,
dl {
  margin-top: 0;
  margin-bottom: 1rem;
}

ol ol,
ul ul,
ol ul,
ul ol {
  margin-bottom: 0;
}

dt {
  font-weight: bold;
}

dd {
  margin-bottom: .5rem;
  margin-left: 0;
}

blockquote {
  margin: 0 0 1rem;
}

dfn {
  font-style: italic;
}

b,
strong {
  font-weight: bolder;
}

small {
  font-size: 80%;
}

sub,
sup {
  position: relative;
  font-size: 75%;
  line-height: 0;
  vertical-align: baseline;
}

sub {
  bottom: -.25em;
}

sup {
  top: -.5em;
}

a {
  color: #007bff;
  text-decoration: none;
  background-color: transparent;
  -webkit-text-decoration-skip: objects;
}

a:hover {
  color: #0056b3;
  text-decoration: underline;
}

a:not([href]):not([tabindex]) {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus, a:not([href]):not([tabindex]):hover {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus {
  outline: 0;
}

pre,
code,
kbd,
samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

pre {
  margin-top: 0;
  margin-bottom: 1rem;
  overflow: auto;
  -ms-overflow-style: scrollbar;
}

figure {
  margin: 0 0 1rem;
}

img {
  vertical-align: middle;
  border-style: none;
}

svg:not(:root) {
  overflow: hidden;
}

a,
area,
button,
[role="button"],
input:not([type=range]),
label,
select,
summary,
textarea {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}

table {
  border-collapse: collapse;
}

caption {
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  color: #868e96;
  text-align: left;
  caption-side: bottom;
}

th {
  text-align: inherit;
}

label {
  display: inline-block;
  margin-bottom: .5rem;
}

button {
  border-radius: 0;
  border: solid 1px #ccc;
  background-color: #ccc;
  overflow: hidden;
}

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

input,
button,
select,
optgroup,
textarea {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button,
input {
  overflow: visible;
}

button,
select {
  text-transform: none;
}

button,
html [type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: button;
}

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  padding: 0;
  border-style: none;
}

input[type="radio"],
input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  -webkit-appearance: listbox;
}

textarea {
  overflow: auto;
  resize: vertical;
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin-bottom: .5rem;
  font-size: 1.5rem;
  line-height: inherit;
  color: inherit;
  white-space: normal;
}

progress {
  vertical-align: baseline;
}

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

[type="search"] {
  outline-offset: -2px;
  -webkit-appearance: none;
}

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

::-webkit-file-upload-button {
  font: inherit;
  -webkit-appearance: button;
}

output {
  display: inline-block;
}

summary {
  display: list-item;
}

template {
  display: none;
}

[hidden] {
  display: none !important;
}

html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, dl,
dt, dd, blockquote, address, table {
  margin: 0;
  padding: 0;
}

* {
  font-weight: 100;
}
/* Master Styles */

a {
  cursor: pointer;
  cursor: hand;
}
button {
  font-family: Arial;
  background-color: #eee;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  cursor: hand;
}
button:hover {
  background-color: #cfd8dc;
}
button:disabled {
  background-color: #eee;
  color: #aaa;
  cursor: auto;
}

/* Navigation link styles */
nav a {
  padding: 5px 10px;
  text-decoration: none;
  margin-right: 10px;
  margin-top: 10px;
  display: inline-block;
  background-color: #eee;
  border-radius: 4px;
  text-decoration: none;
}
nav a:visited, a:link {
  color: #607D8B;
}
nav a:hover {
  color: #039be5;
  background-color: #CFD8DC;
  text-decoration: none;
}
nav a.active {
  color: #039be5;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav li {
  margin: 0;
  padding: 0;
  display: inline-block;
}

/* everywhere else */
* {
  font-family: Arial, Helvetica, sans-serif;
}

/****************/
/* Local Styles */
/****************/
html, body {
  margin: 0;
  padding: 0;
}
body {
  display: flex;
  flex-direction: column;
}
header {
  background-color: #333;
  padding: 20px;
}
header h1 {
  color: #fff;
  margin: 0;
  font-size: 2.5rem;
  font-weight: 100;
}
header a, header a:hover, header a:visited {
  color: #fff !important;
  text-decoration: none !important;
}
section {
  padding: 2rem;
  font-size: 1.5rem;
  flex: 1;
}

/* DashboardComponent's private CSS styles */
[class*='col-'] {
  float: left;
  padding-right: 20px;
  padding-bottom: 20px;
}
[class*='col-']:last-of-type {
  padding-right: 0;
}
.dashboard {
  display: flex;
  flex-direction: column;
}
.dashboard a {
  text-decoration: none;
}
.dashboard *, .dashboard *:after,.dashboard  *:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.dashboard h3 {
  text-align: center; margin-bottom: 0;
  font-size: 2rem;
}
.dashboard h4 {
  position: relative;
  font-size: 1.8rem;
}
.grid {
  margin: 0;
}
.col-1-4 {
  width: 20%;
}
.module {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
  text-align: center;
  color: #eee;
  max-height: 120px;
  min-width: 120px;
  background-color: #607D8B;
  border-radius: 2px;
}
.module h4 {
  margin: 0;
  padding: 0;
}
.module:hover {
  background-color: #EEE;
  cursor: pointer;
  color: #607d8b;
}
.grid-pad {
  padding: 10px 0;
}
.grid-pad > [class*='col-']:last-of-type {
  padding-right: 20px;
}
@media (max-width: 600px) {
  .module h4 {
    font-size: 1.3rem;
  }
  .module {
    max-height: 75px; }
}
@media (max-width: 1024px) {
  .grid {
    margin: 0;
  }
  .module {
    min-width: 60px;
  }
}

/* HeroesComponent's private CSS styles */
.heroes {
  margin: 0 0 2em 0;
  list-style-type: none;
  padding: 0;
  width: 15em;
}
.heroes li {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  cursor: pointer;
  background-color: #EEE;
  margin: .5em 0;
  /* padding: .3em 0; */
  height: 3rem;
  border-radius: 4px;
}

.heroes li:hover {
  color: #607D8B;
  background-color: #DDD;
  left: .1em;
}

.heroes a {
  color: #888;
  text-decoration: none;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  vertical-align: middle;
  width: 250px;
  flex: 1;
}

.heroes a:hover {
  color:#607D8B;
}

.heroes .hero-link {
  display: block;
}

.heroes .badge {
  display: inline-flex;
  align-items: center;
  font-size: small;
  color: white;
  padding: 0 0.7em 0 0.7em;
  background-color: #607D8B;
  line-height: 1em;
  height: 100%;
  min-width: 16px;
  text-align: right;
  margin-right: .8em;
  border-radius: 4px 0 0 4px;
}

.heroes .button {
  background-color: #eee;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  cursor: hand;
  font-family: Arial;
}

.heroes button:hover {
  background-color: #cfd8dc;
}

.heroes button.delete {
  background-color: gray !important;
  color: white;
}

.form--add-hero {
  margin: 10px 0;
}
.form--add-hero input {
  margin: 0 5px;
}
#update-name {
  margin: 0 5px;
}
.hero-detail--buttons {
  margin: 10px 0;
}
.hero-detail--buttons button + button {
  margin-left: 10px;
}

.search-result li {
  border-bottom: 1px solid gray;
  border-left: 1px solid gray;
  border-right: 1px solid gray;
  width:195px;
  /* height: 16px; */
  /* padding: 5px; */
  background-color: white;
  cursor: pointer;
  list-style-type: none;
}

.search-result li:hover {
  background-color: #607D8B;
}

.search-result li a {
  color: #888;
  display: block;
  text-decoration: none;
  padding: 5px 10px;
}

.search-result li a:hover {
  color: white;
}
.search-result li a:active {
  color: white;
}
#search-box {
  width:195px;
}
#search-box:focus {
  outline: none;
}

ul.search-result {
  margin-top: 0;
  padding-left: 0;
}
            
          
!

JS

            
              /** @jsx h */
const { h, Component} = composi

// Mock Data:
const mockHeroes = [
  { "id": "11", "name": "Mr. Nice" },
  { "id": "12", "name": "Narco" },
  { "id": "13", "name": "Bombasto" },
  { "id": "14", "name": "Celeritas" },
  { "id": "15", "name": "Magneta" },
  { "id": "16", "name": "RubberMan" },
  { "id": "17", "name": "Dynama" },
  { "id": "18", "name": "Dr IQ" },
  { "id": "19", "name": "Magma" },
  { "id": "20", "name": "Tornado" }
]


// Title component
const title = new Component ({
  container: 'header',
  state: 'Tour of Heroes',
  render: (message) => <h1><a href="#">{message}</a></h1>
})
  
const menu = new Component({
  container: 'section',
  state: true,
  render: (data) => {
    return (
      <nav>
        <ul>
          <li><a href="#/dashboard">Dashboard</a></li>
          <li><a href="#/heroes">Heroes</a></li>
        </ul>
      </nav>
    )
  }
})

// Hero search
function HeroSearch({search, searchResults, blurSearchInput}) {
  return (
    <div id="search-component">
      <h4>Hero Search</h4>

      <input id="search-box" onkeyup={(e)=> search(e)} onblur={() => blurSearchInput()} />

      {
        searchResults.length > 0 && (
          <ul class="search-result">
            {
              searchResults.map(hero => (
                <li>
                  <a href={`#/detail/${hero.id}`}>{hero.name}</a>
                </li>
              ))
            }
          </ul>
        )
      }
    </div>
  )
}

// Dashboard component
function HeroDashboard({heroes, search, searchResults, blurSearchInput}) {
  const selectHeroes = heroes.slice(1, 5)
  return (
    <div class='dashboard'>
      <h3>Top Heroes</h3>
      <div class="grid grid-pad">
        {
          selectHeroes.map(hero => (
            <a class="col-1-4" href={`#/detail/${hero.id}`}>
              <div class="module hero">
                <h4>{hero.name}</h4>
              </div>
            </a>
          ))
        }
      </div>
      <HeroSearch 
        search={search} 
        searchResults={searchResults}
        blurSearchInput={blurSearchInput} />
    </div>
  )
}

// Hero list component
function HeroList({heroes, deleteItem, addHero}) {

  return (
    <div>
      <p class='form--add-hero'>
        <label htmlFor="add-hero">Hero name: </label>
        <input id='add-hero' type="text"/>
        <button onclick={addHero}>Add</button>
      </p>
      <ul class="heroes">
        {
          heroes.map(hero => (
            <li>
              <a href={`#/detail/${hero.id}`}>
                <span class="badge">{hero.id}</span> 
                <span class='hero-link'>{hero.name}</span>
              </a>
              <button data-id={hero.id} class="delete" title="delete hero"
              onclick={(e) => deleteItem(e)}>x</button>
            </li>
          ))
        }
      </ul>
    </div>
  )
}

// Hero detail
function HeroDetail({hero, onHeroNameChange, resetName, saveName}) {
  return (
    <div id='hero-detail'>
      <h2>{hero.name} details!</h2>
      <div><label>id:</label> {hero.id}</div>
      <div>
        <label for='update-name'>name: </label>
        <input id='update-name' placeholder={hero.name} oninput={(e) => onHeroNameChange(e)} />
      </div>
      <p class='hero-detail--buttons'>
        <button onclick={resetName}>Reset</button>
        <button onclick={saveName}>Save</button>
      </p>
    </div>
  )
}

//////////////////////
// Main App Component:
//////////////////////
class App extends Component {
  constructor(props) {
    super(props) 
    this.container = 'section'
    this.state = {
      activeComponent: 'dashboard',
      heroes: mockHeroes,
      selectedHero: '',
      searchResults: []
    }
  }

  render(state) {
    return (
      <div class="app-root">
        {
          state.activeComponent === 'dashboard' && <HeroDashboard 
            heroes={this.state.heroes}
            search={this.search.bind(this)}
            searchResults={this.state.searchResults} 
            blurSearchInput={this.blurSearchInput.bind(this)} />
        }
        {
         state.activeComponent === 'heroes' && <HeroList 
            heroes={this.state.heroes} 
            deleteItem={this.deleteItem.bind(this)} 
            addHero={this.addHero.bind(this)} />
        }
        {
          state.activeComponent === 'detail' && 
            <HeroDetail 
              hero={this.state.selectedHero} 
              deleteItem={this.deleteItem}
              onHeroNameChange={this.onHeroNameChange.bind(this)} 
              resetName={this.resetName.bind(this)} 
              saveName={this.saveName.bind(this)} />
        }
      </div>
    )
  }
  
  componentDidMount() {
    setupRoutes(this)
  }

  search(e) {
    const input = e.target
    const value = input.value
    const heroes = this.state.heroes
    const searchResults = heroes.filter(hero => {
      const name = hero.name.toLowerCase()
      return name.match(value.toLowerCase())
    })
    this.setState({searchResults: searchResults})
  }

  blurSearchInput(e) {
    const searchResults = this.state.searchResults
    setTimeout(() => {
      this.setState({searchResults: []})
    }, 250)
  }

  addHero(e) {
    const input = e.target.parentNode.querySelector('#add-hero')
    const value = input.value
    if (value) {
      const lastId = this.state.heroes[this.state.heroes.length -1].id
      const newHero = {id: String(parseInt(lastId) + 1), name: value}
      const heroes = this.state.heroes
      heroes.push(newHero)
      this.setState({heroes})
      input.value = ''
    }
  }

  deleteItem(e) {
    const id = e.target.dataset.id
    const heroes = this.state.heroes
    const position = heroes.findIndex(hero => id == hero.id)
    heroes.splice(position, 1)
    this.setState({heroes})
  }
  
  onHeroNameChange(e) {
    const value = e.target.value
    if (value) {
      const selectedHero = this.state.selectedHero
      selectedHero.name = value
      this.setState({selectedHero})
    }
  }

  resetName(e) {
    const selectedHero = this.state.selectedHero
    selectedHero.name = selectedHero.originalName
    this.setState({selectedHero})
  }

  saveName(e) {
    window.location.hash = '#/heroes'
  }
}


// Define routes:
function setupRoutes(self) {
  router({
    '': function() {
      self.setState({activeComponent: 'dashboard'})
    },
    '/dashboard': function() {
      self.setState({activeComponent: 'dashboard'})
    },
    '/heroes': function() {
      self.setState({activeComponent: 'heroes'})
    },
    '/detail/:id': function(id) {
      const state = app.state
      const position = state.heroes.findIndex(person => person.id === id)
      const hero = state.heroes[position]
      hero.originalName = hero.name
      app.setState({activeComponent: 'detail', selectedHero: hero})
    }
  })
}

// Instantiate App:
const app = new App()
            
          
!
999px

Console