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

              
                <div class="container">

	<span class="js-typed-src">
		<h1 class="page-title">Hey, this is typed using <a href="https://github.com/mattboldt/typed.js/">Typed.js</a>!</h1>
	</span>
	<span class="js-typed"></span>

	<span class="js-typed-src">
		<h2>I wanted to type out an entire page of text rather than a single line which is how it is usually used.</h2>
	</span>
	<span class="js-typed"></span>

	<span class="js-typed-src" data-speed="20">
		<p>I figured out a way to cycle through an array of elements and apply a new Typed instance to each one using a recursive function. This section is typed faster because of a data attribute used to apply a different typing speed per section.</p>
		<img class="page-image" src="http://3.bp.blogspot.com/-DT6OM3ShPZk/VGmsJb1hCkI/AAAAAAAARm0/JxQao_QFhGs/s1600/caloria.jpg">
		<p>You'll notice there are a few paragraph tags in this section, and even an image! The plugin is moving through all of this text and doesn't care about the markup.</p>
		<p>All of the text already exists in an element with the class <code>.js-typed-src</code> that is visually hidden. Then, there is an empty <code>&lt;span></code> below each with the class <code>.js-typed</code>. The plugin retrieves the HTML from the aforementioned <code>.js-typed-src</code> element and types it into the empty <code>span.js-typed</code>. This flow could probably be improved, plus it <em>may</em> read twice for screen readers &dash; I still have to test that.</p>
	</span>
	<span class="js-typed"></span>
	
	<span class="js-typed-src">
		<p>Anyhow, I'm finally learning JavaScript...for real this time!</p>
	</span>
	<span class="js-typed"></span>

</div>
              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

body {
	line-height: 1.4;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

a {
	color: skyblue;
	text-decoration: none;
	&:hover {
		color: lightslategray;
	}
}

img {
	max-width: 100%;
	height: auto;
}

// Hidden for accessibility
.js-typed-src {
	opacity: 0;
	position: absolute;
	left: -99999px;
}

.container {
	max-width: 600px;
	margin: 2rem auto;
	padding: 1rem;
}

.page-title {
	margin-top: 0;
}

.page-image {
	display: block;
	margin: 1rem auto;
}
              
            
!

JS

              
                // Get an array of all elements to be typed.
const TYPED_SRCS = document.querySelectorAll('.js-typed-src');
const TYPED_ELS = document.querySelectorAll('.js-typed');
const TYPE_SPEED = 40,
			SHOW_CURSOR = false;

var options = {
	elIndex: 0,
	strings: [TYPED_SRCS[0].innerHTML],
	typeSpeed: TYPE_SPEED,
	showCursor: SHOW_CURSOR,
	onComplete: () => {
		typeNextInArray();
	},
}

// Start the typing elements, starting with index 0
var typed = new Typed(TYPED_ELS[0], options);

// Function to type next item in typedEls array
function typeNextInArray() {

	// Move through the array
	options.elIndex++;
	let newIndex = options.elIndex;
	let currentEl = TYPED_SRCS[newIndex];

	// Allow for data attributes to provide some settings
	let newTypeSpeed = "speed" in currentEl.dataset ? +currentEl.dataset.speed : TYPE_SPEED;
	// More options could be added to / retrieved via data attributes here!

	// New options set
	let newOptions = {
		elIndex: newIndex,
		startDelay: 500,
		strings: [TYPED_SRCS[newIndex].innerHTML],
		typeSpeed: newTypeSpeed,
		showCursor: SHOW_CURSOR,
		onComplete: () => {
			if (newIndex + 1 <= TYPED_ELS.length - 1) {
				return typeNextInArray();
			} else {
				console.log('done');
			}
		}
	}

	let typed = new Typed(TYPED_ELS[newIndex], newOptions);
}
              
            
!
999px

Console