HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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><head></code> and the JS is loaded just before the closing <code></body></code> tag:</p>
<pre><code><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/htmltypist.js/dist/typist.css">
<script src="https://cdn.jsdelivr.net/npm/htmltypist.js/dist/typist.js"></script></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><p class="typist">Type and retype this paragraph forever!</p></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><p class="typist" data-typist-repeat="1">This paragraph is typed once.</p></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><p class="typist"> <span>This is typed first.</span> <span>This is typed second.</span> <span>This is typed third.</span> </p></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><ul> <li class="typist" data-typist-repeat="1" data-typist-sequence="mylist">item one</li> <li class="typist" data-typist-repeat="1" data-typist-sequence="mylist">item two</li> <li class="typist" data-typist-repeat="1" data-typist-sequence="mylist">item three</li> </ul></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><p class="typist" data-typist-repeat="3" data-typist-delay-type="400" data-typist-delay-vary="0.25">This will be typed.</p></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>
Also see: Tab Triggers