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 id="app"></div>
              
            
!

CSS

              
                // colors
$white: #fefefe;
$prim: #f6d2c6;
$prim-lt: lighten(#f6d2c6, 5%);
$sec: #00a547;
$sec-lt: lighten(#7de1af, 10%);
$tert: #6768da;
$tert-lt: lighten($tert, 35%);

// fonts
$mono-fam: "Anonymous Pro", Consolas, "Andale Mono WT", "Andale Mono",
	"Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono",
	"Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco,
	"Courier New", Courier, monospace;
$sans-fam: -apple-system, BlinkMacSystemFont, "avenir next", avenir, "Segoe UI",
	"lucida grande", "helvetica neue", helvetica, "Fira Sans", roboto, noto,
	"Droid Sans", cantarell, oxygen, ubuntu, "franklin gothic medium",
	"century gothic", "Liberation Sans", sans-serif; /* Everything else */

// spacing
$base: 4px;

::selection {
	background-color: $sec-lt;
}

::moz-selection {
	background-color: $sec-lt;
}

* {
	box-sizing: border-box;
}

body,
html {
	height: 100%;
	margin: 0;
	padding: 0;
	color: #222;
	background-color: #f9f9f9;
}

.markdown-app {
	display: flex;
	flex-direction: column;
}

.panes {
	display: flex;
	flex-direction: column;
	height: 100vh;
	padding: 1rem;
}

.pane {
	height: 50%;
	width: 100%;
	overflow: hidden;
	border: $base * 2 solid $prim-lt;
	border-top: none;
	transition: height 250ms ease-in-out;

	& + .pane {
		margin-top: $base * 3;
	}

	&.minimize {
		height: 10%;
	}

	&.minimize textarea {
		height: 0;
	}

	&.expanded {
		height: 90%;
	}
}

.pane__preview-output {
	padding: 1rem;
	overflow-y: auto;
	height: 90%;
	background-color: $white;
	font-family: $sans-fam;
}

header {
	padding: 1rem 0.5rem;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	background-color: $prim-lt;
	font-family: $mono-fam;

	h2 {
		margin: 0;
		padding: 0 $base $base 0;
		font-size: 1.2rem;
		letter-spacing: 1px;
		text-transform: uppercase;
		border-bottom: $base solid;
		border-image: linear-gradient(40deg, #50ffa3, #ff9673);
		border-image-slice: 1;
	}
}

nav {
	display: flex;
	text-align: center;
}

textarea {
	color: #222;
	width: 100%;
	height: 80%;
	max-height: 100%;
	overflow-y: auto;
	padding: 1rem;
	background-color: $white;
	font-family: $mono-fam;
	font-size: 1.05em;
	border: none;
	resize: none;
	transition: height 250ms ease-in-out;

	&:focus {
		outline: none;
		background-color: $prim-lt;
		background-color: lighten($prim-lt, 6%);
	}
}

pre {
	padding: ($base * 2) $base;
	overflow-x: auto;
	max-width: 84ch;
	margin: auto;
	color: darken($prim, 40%);
	background-color: $prim-lt;

	& code {
		background-color: transparent;
		border: none;
		color: inherit;
	}
}

a {
	color: $tert;
	text-decoration: none;
	padding-bottom: 1px;
	border-bottom: 2px solid #7de1af;
	transition: background-color 150ms ease-in-out;

	&:hover,
	&:focus {
		background-color: $sec-lt;
		border-bottom-color: $white;
		outline: none;
		color: #222;
	}
}

strong {
	color: #06bd5d;
}

em {
	color: #6768da;
}

p {
	line-height: 1.5;
}

code {
	padding: 0 4px;
	border: 1px solid;
	background-color: $tert-lt;
	color: $tert;
}

button {
	border: none;
	font-family: inherit;
	background-color: transparent;
	font-size: 1.2em;
	font-weight: bold;
	cursor: pointer;
	transition: color 200ms ease-in-out;

	&:focus {
		outline: 1px solid;
		color: $tert;
	}
	&:hover {
		color: $tert;
	}
}

[id^="icon-"] {
	display: inline-block;
	stroke-width: 0;
	stroke: currentColor;
	fill: currentColor;
	width: 1.5rem;
	height: 1.5rem;
	vertical-align: middle;
}

img {
	max-width: 100%;
}

blockquote {
	background-color: lighten($tert, 35%);
	padding: 1rem;
	font-style: italic;
	font-size: 1.25rem;
	color: $tert;
	max-width: 40rem;
	margin: auto;
	word-break: break-all;
}

ul {
	list-style: none;
}

.sr-only {
	border: 0 !important;
	clip: rect(1px, 1px, 1px, 1px) !important;
	-webkit-clip-path: inset(50%) !important;
	clip-path: inset(50%) !important;
	height: 1px !important;
	overflow: hidden !important;
	padding: 0 !important;
	position: absolute !important;
	width: 1px !important;
	white-space: nowrap !important;
}

@media screen and (min-width: 65em) {
	.panes {
		flex-direction: row;
	}

	.pane {
		width: 50%;
		height: auto;
		margin: 0 $base * 1.5;
		transition: width 250ms ease-in-out;
 
		& + .pane {
			margin-top: 0;
		}
		
		&.minimize {
			width: 13%;
			height: auto;
		}

		&.minimize header {
			flex-direction: column;
		}

		&.minimize textarea {
			height: 100%;
			transition: none;
		}

		&.minimize nav {
			margin-top: 0.5rem;
		}

		&.expanded {
			width: 87%;
			height: auto;
		}

		textarea {
			height: 90%;
		}
	}
}

              
            
!

JS

              
                const { Component } = React;

class NavBar extends Component {
	constructor(props) {
		super(props);
		this.fsToggle = this.fsToggle.bind(this);
	}

	fsToggle(e) {
		this.props.expand(this.props.heading);
	}

	render() {
		let buttons = [
			<Button
				handler={this.fsToggle}
				label={this.props.expanded ? "exit expanded view" : "expand view"}
				icon={this.props.expanded ? <MinIcon /> : <ExpandIcon />}
			/>
		];

		if (this.props.view === "editor") {
			buttons.unshift(
				<Button handler={this.props.clear} label="clear" icon={<ClearIcon />} />
			);
		}

		return (
			<header>
				<h2 id={this.props.heading}>{this.props.heading}</h2>
				<nav>{buttons}</nav>
			</header>
		);
	}
}

const Button = props => (
	<button
		className={props.classes}
		onClick={props.handler}
		aria-label={props.label}
	>
		{props.icon}
	</button>
);

const ClearIcon = () => (
	<svg
		id="icon-trash-o"
		width="20"
		height="20"
		xmlns="http://www.w3.org/2000/svg"
		viewBox="0 0 22 28"
		aria-labelledby="clear"
	>
		<title id="clear">clear markdown</title>
		<path d="M8 11.5v9c0 0.281-0.219 0.5-0.5 0.5h-1c-0.281 0-0.5-0.219-0.5-0.5v-9c0-0.281 0.219-0.5 0.5-0.5h1c0.281 0 0.5 0.219 0.5 0.5zM12 11.5v9c0 0.281-0.219 0.5-0.5 0.5h-1c-0.281 0-0.5-0.219-0.5-0.5v-9c0-0.281 0.219-0.5 0.5-0.5h1c0.281 0 0.5 0.219 0.5 0.5zM16 11.5v9c0 0.281-0.219 0.5-0.5 0.5h-1c-0.281 0-0.5-0.219-0.5-0.5v-9c0-0.281 0.219-0.5 0.5-0.5h1c0.281 0 0.5 0.219 0.5 0.5zM18 22.813v-14.812h-14v14.812c0 0.75 0.422 1.188 0.5 1.188h13c0.078 0 0.5-0.438 0.5-1.188zM7.5 6h7l-0.75-1.828c-0.047-0.063-0.187-0.156-0.266-0.172h-4.953c-0.094 0.016-0.219 0.109-0.266 0.172zM22 6.5v1c0 0.281-0.219 0.5-0.5 0.5h-1.5v14.812c0 1.719-1.125 3.187-2.5 3.187h-13c-1.375 0-2.5-1.406-2.5-3.125v-14.875h-1.5c-0.281 0-0.5-0.219-0.5-0.5v-1c0-0.281 0.219-0.5 0.5-0.5h4.828l1.094-2.609c0.313-0.766 1.25-1.391 2.078-1.391h5c0.828 0 1.766 0.625 2.078 1.391l1.094 2.609h4.828c0.281 0 0.5 0.219 0.5 0.5z" />
	</svg>
);

const ExpandIcon = () => (
	<svg
		id="icon-expand"
		viewBox="0 0 32 32"
		width="20"
		height="20"
		xmlns="http://www.w3.org/2000/svg"
		aria-labelledby="expand"
	>
		<title id="expand">expand</title>
		<path d="M13.816 5.989l-7.785 0.046 0.003 7.735 2.59-2.591 3.454 3.454 2.665-2.665-3.453-3.454 2.526-2.525zM12.079 17.35l-3.454 3.455-2.59-2.592-0.003 7.799 7.785-0.018-2.526-2.525 3.454-3.453-2.666-2.666zM19.922 14.633l3.453-3.454 2.59 2.591 0.004-7.735-7.785-0.046 2.526 2.525-3.454 3.454 2.666 2.665zM23.375 20.805l-3.453-3.455-2.666 2.666 3.454 3.453-2.526 2.525 7.785 0.018-0.004-7.799-2.59 2.592z" />
	</svg>
);

const MinIcon = () => (
	<svg
		id="icon-min"
		viewBox="0 0 20 20"
		width="20"
		height="20"
		xmlns="http://www.w3.org/2000/svg"
		aria-labelledby="exit-expand"
	>
		<title id="exit-expand">exit expanded view</title>
		<path d="M10 20c-5.523 0-10-4.477-10-10s4.477-10 10-10v0c5.523 0 10 4.477 10 10s-4.477 10-10 10v0zM10 18c4.418 0 8-3.582 8-8s-3.582-8-8-8v0c-4.418 0-8 3.582-8 8s3.582 8 8 8v0zM15 9v2h-10v-2h10z" />
	</svg>
);

class Editor extends Component {
	constructor(props) {
		super(props);
	}

	render() {
		return (
			<section
				className={
					"pane pane__edit" +
					(this.props.expanded === "Markdown"
						? " expanded"
						: this.props.expanded === "Preview" ? " minimize" : "")
				}
			>
				<NavBar
					heading="Markdown"
					clear={this.props.clear}
					expand={this.props.expanding}
					view="editor"
					expanded={this.props.expanded === "Markdown"}
				/>
				<textarea
					aria-labelledby="Markdown"
					id="editor"
					value={this.props.markdown}
					onChange={this.props.handler}
				/>
			</section>
		);
	}
}

class Preview extends Component {
	constructor(props) {
		super(props);
	}

	render() {
		const markup = marked(this.props.markdown, {
			sanitze: true,
			gfm: true,
			breaks: true,
			headerIds: true
		});

		return (
			<section
				className={
					"pane pane__preview" +
					(this.props.expanded === "Preview"
						? " expanded"
						: this.props.expanded === "Markdown" ? " minimize" : "")
				}
			>
				<NavBar
					heading="Preview"
					expand={this.props.expanding}
					expanded={this.props.expanded === "Preview"}
				/>
				<div
					id="preview"
					className="pane__preview-output"
					dangerouslySetInnerHTML={{ __html: markup }}
				/>
			</section>
		);
	}
}

class App extends Component {
	constructor(props) {
		super(props);

		this.state = {
			markdown: [
				"# Cats Win!\n\n",
				"![Meet the new boss](http://placekitten.com/320/220)\n\n",
				`> “What greater gift than the love of a cat.” ― Charles Dickens\n\n`,
				"## About Your New Feline Overlords\n\n",
				`Don't panic! Cats can sense fear. [This guide to pleasing your new feline overlords](https://google.com) should help you during this initial transition period.\n\n`,
				"Should you start to feel yourself getting nervous, remember, there is always the `esc` button.\n\n",
				`Looking at some **JavaScript** might help you better understand what is going on, so here's a code sample to bring you up to speed:\n\n`,
				"```javascript\n const inCharge = who => {\n\tif (who === 'humans') {\n \t\treturn `I'm sorry, but humans are not in charge. I think you meant to say 'cats'.`;\n\t} else if (who === 'dogs') {\n\t\t return `That is not how you spell 'cats'.`;\n  \t}\n\n\treturn `That's right! Cats are in charge.`;\n};```\n\n",
				,
				"## First Steps to Getting to Know the C.A.T.S. in Charge\n\n",
				`Cats are relatively easy to please, as long as you do everything they want. Here's a list of some things you can do to immediately impress your new cat overlords.\n\n
`,
				"- **Stop thinking anything is yours**\n\n",
				`\tUp until now, you've been living under the impression that everything you own belongs to you. In reality, you have just been a keeper of items. Now that cats are officially in charge, you will quickly learn that what's yours is theirs and what's theirs is also theirs.\n\n`,
				"- **Cats will starve to death even with a full bowl of food**\n\n",
				`\tI know this seems unlikely, but if you do not put fresh food down every few hours, even with a full bowl of food already down, your cat overlord will starve to death. Don't worry! If you forget, the cat will remind you. Cats realize humans do not have the intelligence to remember food time on their own.
\n\tAll cats come with built in alarms. For the cat's safety, these alarms can only be turned off by putting down fresh food.\n\n`,
				"- **Never touch your cat outside of the permitted pet zones***\n\n",
				`\tBut also be sure to give a lot of pets. Just not too many because then you will cause overstimulation in the cat, and you will be punished.

\n\n ** \tpermitted pet zones vary per cat and are subject to change from second to second.*
`
			].join(""),
			markup: "",
			status: "",
			isExpanded: false,
			fsPane: ""
		};

		this.updateMarkdown = this.updateMarkdown.bind(this);
		this.clear = this.clear.bind(this);
		this.expand = this.expand.bind(this);
	}

	expand(val) {
		if (val === this.state.fsPane) {
			this.setState({
				isExpanded: false,
				fsPane: ""
			});
		} else if (this.fsPane && this.isExpanded) {
			this.setState({
				fsPane: val
			});
		} else {
			this.setState({
				fsPane: val,
				isExpanded: true
			});
		}
	}

	updateMarkdown(e) {
		if (this.state.status) {
			this.setState({
				status: ""
			});
		}

		this.setState({
			markdown: e.target.value
		});
	}

	clear() {
		this.setState({
			markdown: "",
			status: "Markdown cleared"
		});
	}

	render() {
		return (
			<div className="markdown-app">
				<h1 className="sr-only">Simple React Markdown Editor and Preview App</h1>
				<main className="panes">
					<Editor
						handler={this.updateMarkdown}
						markdown={this.state.markdown}
						clear={this.clear}
						expanding={this.expand}
						expanded={this.state.fsPane}
						isExpanded={this.state.isExpanded}
					/>
					<Preview
						markdown={this.state.markdown}
						expanding={this.expand}
						expanded={this.state.fsPane}
						isExpanded={this.state.isExpanded}
					/>
				</main>
				<p className="sr-only" id="status" aria-live="polite">
					{this.state.status}
				</p>
			</div>
		);
	}
}

ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console