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 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

              
                <div class="container">
  <div id="root"></div>
</div>

              
            
!

CSS

              
                *
  box-sizing: border-box

html,
body
  font-family: sans-serif
  
.container
  margin: 0 auto
  max-width: 600px

.tags-input
  display: inline-flex
  margin: 0 auto
  padding: 5px
  width: 600px
  font-size: 14px
  border: #cecece solid 1px
  border-radius: 3px
  
  .tag
    margin-right: 5px
  
  input
    width: 100%
    border: none
    outline: none
    
.tag
  display: inline-flex
  padding: 2px 5px
  background-color: #cecece
  border-radius: 3px
  
button.delete
  display: inline-block
  margin-left: 5px
  padding: 0
  width: 15px
  height: 15px
  background-color: rgba(0,0,0,.3)
  color: white
  font-size: 10px
  font-weight: bold
  cursor: pointer
  border-radius: 50px
  border: none
  outline: none
  user-select: none
  
  &:after
    content: 'X'
    width: 15px
    height: 15px
    line-height: 15px
    text-align: center
  
.help
  font-size: 12px
  color: #555

              
            
!

JS

              
                const Tag = props => <span className="tag" {...props} />
const Delete = props => <button className="delete" {...props} />
const Help = props => <span className="help" {...props} />

class TagsInput extends React.Component {
  constructor () {
    super()
    this.state = {
      newTag: ''
    }
    
    this.handleChange = this.handleChange.bind(this)
    this.handleKeyDown = this.handleKeyDown.bind(this)
    this.handleRemoveTag = this.handleRemoveTag.bind(this)
  }
  
  handleChange (e) {
    this.setState({ newTag: e.target.value })
  }
  
  handleKeyDown (e) {
    if (e.keyCode === 13 && e.target.value !== '')  {
      let newTag = this.state.newTag.trim()

      if (this.props.value.indexOf(newTag) === -1) {
        this.props.value.push(newTag)
        this.setState({ newTag: '' })
      }
      e.target.value = ''
    }
  }
  
  handleRemoveTag (e) {
    let tag = e.target.parentNode.textContent.trim()
    let index = this.props.value.indexOf(tag)
    this.props.value.splice(index, 1)
    this.setState({ newTag: '' })
  }
  
  render () {
    return (
      <div>
        <div className="tags-input">
          {this.props.value.map((tag, index) => (
            <Tag>
              {tag}
              <Delete onClick={this.handleRemoveTag} />
            </Tag>
          ))}
          <input type="text" 
            onChange={this.handleChange}
            onKeyDown={this.handleKeyDown} />
        </div>
        <Help>hit 'Enter' to add new tags</Help>
      </div>
    )
  }
}

class App extends React.Component {
  constructor () {
    super()
    this.state = {
      tags: ['javascript', 'react']
    }
  }
  
  handleTagsChange (tags) {
    this.setState({ tags: tags })
  }
  
  render () {
    return (
      <TagsInput value={this.state.tags} onChange={this.handleTagsChange} />
    )
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
)

              
            
!
999px

Console