cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="rich-editor">
  <div class="wrapper">
    <div class="editor-area" contenteditable="true" placeholder="Enter text here..."></div>
    <div class="editor-backer"></div>
  </div>
  <span class="counter">140</span>
</div>
            
          
!
            
              html,
body {
  display: flex;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background: #E3F3FD;
  font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}

.rich-editor {
  width: 508px;
  height: auto;
 /* max-height: 134px;
  overflow-y: scroll;*/
  margin: auto;
  padding: 8px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #A4D9F9;
  box-shadow: 0 0 0 1px #A4D9F9;
}
.wrapper {
  position: relative;
  width: 100%;
  min-height: 116px;
  z-index: 1;

}
.editor-area, .editor-backer {
  width: 100%;
  height: auto;
  min-height: 116px;

  font-size: 14px;
  line-height: 20px;
  word-wrap: break-word;
  background: transparent;
}
.editor-area {
  outline: none;
  border: none;

}
.editor-area.is-showPlaceholder[contenteditable=true]:before {
  content: attr(placeholder);
  color: #ccd6dd;
  position: absolute;
}
.editor-backer {
  position: absolute;
  left: 0;
  top: 0;
  color: transparent;
  z-index: -1;
}
.editor-backer em {
  background-color: #ffb8c2;
  font-style: normal;
  font-size: 14px;
  line-height: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.counter {
  float: right;
  color: #657786;
  font-size: 14px;
  line-height: 20px;
  text-align: right;
  user-select: none;
}
.counter.max-reached {
  color: #e0245e;
}
            
          
!
            
              var editorArea = document.querySelector('.editor-area')
var editorBacker = document.querySelector('.editor-backer')
var counter = document.querySelector('.counter')
var limitCnt = 140
var isComposing = false

editorArea.addEventListener('compositionstart', () => {
  isComposing = true
})
editorArea.addEventListener('compositionend', () => {
  isComposing = false
  //
  let text = editorArea.innerText
  setCounter(limitCnt - text.length)
})

function setCounter (cnt) {
  counter.innerHTML = cnt
  if (cnt < 0) {
    counter.classList.add('max-reached')
  } else {
    counter.classList.remove('max-reached')
  }
}

var inputCompose = function () {
  if (editorArea.innerHTML === '<div><br></div>' ||
    editorArea.innerHTML === '<br>' ||
    editorArea.innerHTML === '') {
    editorArea.classList.add('is-showPlaceholder')
  } else {
    editorArea.classList.remove('is-showPlaceholder')
  }

  let text = editorArea.innerText
  let remainingCnt = limitCnt - text.trim().length
  if (remainingCnt < 0) {
    let allowedText = text.substring(0, limitCnt)
    let refusedText = text.substring(limitCnt)

    editorBacker.innerHTML = allowedText + '<em>' + refusedText + '</em>'
  } else {
    editorBacker.innerHTML = ''
  }

  if (!isComposing) {
    setCounter(remainingCnt)
  }
}

inputCompose();
editorArea.oninput = inputCompose
            
          
!
999px
Loading ..................

Console