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

              
                <main>

  <article>

    <h1 class="typist" data-typist-repeat="1" data-typist-cursor-show="2" data-typist-sequence="intro">typist.js</h1>

    <p><a href="https://github.com/craigbuckler/typist.js"><strong>GitHub</strong></a> | <a href="https://www.npmjs.com/package/htmltypist.js"><strong>npm</strong></a> | <a href="https://gum.co/OWTuG"><strong>donate</strong></a> | <a href="https://twitter.com/craigbuckler">@craigbuckler</a> | <a href="https://craigbuckler.com/">craigbuckler.com</a></p>

    <p class="typist" data-typist-sequence="intro">
      <span>typist.js shows a typing effect.</span>
      <span>typist.js works on any website.</span>
      <span>typist.js is lightweight.</span>
      <span>typist.js is easy to configure from HTML.</span>
    </p>

    <p>typist.js can be applied to any HTML element or parent element to type the content.</p>

    <p>Please use the code as you wish. <a href="https://twitter.com/craigbuckler">Tweet me @craigbuckler</a> if you find it useful and <a href="https://gum.co/OWTuG">donate toward development</a> if you use it commercially.</p>

    <ul>
      <li class="typist" data-typist-repeat="1" data-typist-sequence="benefit" data-typist-delay-type="50" data-delay-start="2000">lightweight: 2,800 bytes of JavaScript, 160 bytes of optional CSS</li>
      <li class="typist" data-typist-repeat="1" data-typist-sequence="benefit" data-typist-delay-type="50">no external dependencies - works with any framework</li>
      <li class="typist" data-typist-repeat="1" data-typist-sequence="benefit" data-typist-delay-type="50">easy to configure from HTML</li>
      <li class="typist" data-typist-repeat="1" data-typist-sequence="benefit" data-typist-delay-type="50">works in all modern browsers</li>
      <li class="typist" data-typist-repeat="1" data-typist-sequence="benefit" data-typist-delay-type="50">progressively-enhanced to avoid failure in older browsers.</li>
    </ul>

    <h2>Basic example</h2>

    <p>The page must load the CSS and JavaScript. It can be placed anywhere but, typically, the CSS is loaded in the <code>&lt;head&gt;</code> and the JS is loaded just before the closing <code>&lt;/body&gt;</code> tag:</p>

    <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/htmltypist.js/dist/typist.css&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/htmltypist.js/dist/typist.js&quot;&gt;&lt;/script&gt;</code></pre>

    <p>CDN URLs are shown above but you can also <code>npm i htmltypist.js</code> to install via npm and use a bundler.</p>

    <p>To apply a typing effect to any element, add <code>class="typist"</code> to any element:</p>

    <pre><code>&lt;p class=&quot;typist&quot;&gt;Type and retype this paragraph forever!&lt;/p&gt;</code></pre>

    <p class="typist">Type and retype this paragraph forever!</p>

    <p>A number of <code>data</code> attributes are available. For example, set <code>data-typist-repeat="1"</code> to type once only:</p>

    <pre><code>&lt;p class=&quot;typist&quot; data-typist-repeat=&quot;1&quot;&gt;This paragraph is typed once.&lt;/p&gt;</code></pre>

    <p class="typist" data-typist-repeat="1">This paragraph is typed once.</p>

    <h2>Multiple elements</h2>

    <p>When an element has two or more child elements, their text is typed in sequence:</p>

    <pre><code>&lt;p class=&quot;typist&quot;&gt;&#10;  &lt;span&gt;This is typed first.&lt;/span&gt;&#10;  &lt;span&gt;This is typed second.&lt;/span&gt;&#10;  &lt;span&gt;This is typed third.&lt;/span&gt;&#10;&lt;/p&gt;</code></pre>

    <p class="typist">
      <span>This is typed first.</span>
      <span>This is typed second.</span>
      <span>This is typed third.</span>
    </p>

    <p>"This is typed" is consistent across all sentences so it is never deleted.</p>

    <h2>JavaScript usage</h2>

    <p>typist.js can be dynamically applied in JavaScript by passing a single element to a new <code>Typist</code> object:</p>

    <pre><code>new Typist( document.getElementById('myelement') );</code></pre>

    <h2>typist.js options</h2>

    <p>The following options can be set as HTML5 attributes on any child element or the parent to set across all child elements:</p>

    <table summary="typist.js options">

      <thead>
        <tr>
          <th>HTML5 attribute</th>
          <th>description</th>
        </tr>
      </thead>

      <tbody>

        <tr>
          <td><code>class="typist"</code></td>
          <td>set element to type</td>
        </tr>

        <tr>
          <td><code>data-typist-repeat="N"</code></td>
          <td>repeat typing N times (default: repeat forever)</td>
        </tr>

        <tr>
          <td><code>data-typist-delay-start="M"</code></td>
          <td>delay typing for M milliseconds after the element is scrolled into view (0)</td>
        </tr>

        <tr>
          <td><code>data-typist-delay-type="M"</code></td>
          <td>pause for M milliseconds between each character (100)</td>
        </tr>

        <tr>
          <td><code>data-typist-delay-delete="M"</code></td>
          <td>pause for M milliseconds between delete keypresses (50)</td>
        </tr>

        <tr>
          <td><code>data-typist-delay-vary="F"</code></td>
          <td>randomly vary the typing speed (0.5 - characters are therefore typed between 50ms and 150ms)</td>
        </tr>

        <tr>
          <td><code>data-typist-delay-end="M"</code></td>
          <td>pause for M milliseconds before typing the next item (2000)</td>
        </tr>

        <tr>
          <td><code>data-typist-delete="N"</code></td>
          <td>0 to retain existing text where possible, 1 to delete all (0)</td>
        </tr>

        <tr>
          <td><code>data-typist-cursor="CLASS"</code></td>
          <td>cursor style CSS class (cursor)</td>
        </tr>

        <tr>
          <td><code>data-typist-cursor-show="N"</code></td>
          <td>0 for no cursor, 1 to show cursor until typing completes, 2 to show cursor forever (1)</td>
        </tr>

        <tr>
          <td><code>data-typist-sequence="NAME"</code></td>
          <td>type elements in page DOM order - each completes one animation before the next element is typed</td>
        </tr>

      </tbody>

    </table>

    <p>The following named sequence example types each list item in turn when the first is scrolled into view:</p>

    <pre><code>&lt;ul&gt;&#10;  &lt;li class=&quot;typist&quot; data-typist-repeat=&quot;1&quot; data-typist-sequence=&quot;mylist&quot;&gt;item one&lt;/li&gt;&#10;  &lt;li class=&quot;typist&quot; data-typist-repeat=&quot;1&quot; data-typist-sequence=&quot;mylist&quot;&gt;item two&lt;/li&gt;&#10;  &lt;li class=&quot;typist&quot; data-typist-repeat=&quot;1&quot; data-typist-sequence=&quot;mylist&quot;&gt;item three&lt;/li&gt;&#10;&lt;/ul&gt;</code></pre>

    <p>The following code types text three times using a delay of 300-500ms between characters once it appears in view:</p>

    <pre><code>&lt;p&#10;  class=&quot;typist&quot;&#10;  data-typist-repeat=&quot;3&quot;&#10;  data-typist-delay-type=&quot;400&quot;&#10;  data-typist-delay-vary=&quot;0.25&quot;&gt;This will be typed.&lt;/p&gt;</code></pre>

    <h2>CSS options</h2>

    <p>typist.css is optional and only required for the cursor character and animation which can be configured as necessary.</p>

    <p>A <code>typist</code> class is applied to all elements being typed; global styles can be applied if required.</p>

    <h2>Usage notes</h2>

    <ol>
      <li>Default settings can be changed in the <code>propDefault</code> variable.</li>
      <li>Older browsers (IE11 and below) show all text and do not animate.</li>
    </ol>

  </article>

</main>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console