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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <section>
	<div class="container">
		<h1>CodeMirror #4 - Configuration</h1>
		<p>You can configurate your CodeMirror editor with the options object. Look at the JavaScript section to see what I'm talking about. Or read <a href="http://codemirror.net/doc/manual.html" target="_blank">the CodeMirror documentation page</a> for more info.</p>
<div class="code-container">
	<textarea id="code">
<!-- xml/html syntax -->
<!DOCTYPE html>
<html>
	<head>
		<!-- meta -->
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<!-- title -->
		<title>Example website</title>

		<!-- css -->
		<style type="text/css">
			/* css syntax */
			* {
				margin: 0;
				padding: 0;
			}
			html {
				font-family: 'Arial', sans-serif;
			}
		</style>

		<!-- scripts -->
		<script type="text/javascript">
			window.onload = () => {
				// js syntax
				function init(ok) {
					return ok;
				}
			}
		</script>
	</head>
	<body>
		<section>
			<div class="container">
				<h1>Example website</h1>
				<p>This is just a HTML example</p>
			</div>
		</section>
		<errorDetection see below
	</body>
</html>
	</textarea>
</div>
		<div class="row">
			<a class="btn btn-left" href="https://codepen.io/DerkJanS/pen/EXMwVz" target="_blank">Previous CodeMirror</a>
<!-- 			<a class="btn btn-right" href="https://codepen.io/DerkJanS/pen/owVGZb" target="_blank">Next CodeMirror</a> -->
		</div>
	</div>
</section>
              
            
!

CSS

              
                /**
 *
 * In this pen:
 * added stylesheets with CDN:
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/codemirror.css
*   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/theme/material.css
 *
 */

*, *:after, *:before {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
html,
body {
	height: 100%;
}
html {
	background: #fff;
	text-rendering: optimizeLegibility;
	line-height: 1.5em;
	letter-spacing: .3px;
	font-family: 'Poppins', sans-serif;
	-webkit-text-size-adjust: 100%;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}
body {
	color: #151515;
}
html {
	font-family: 'Geneva', sans-serif;
}


/* ----------
	WRAPPERS & CONTAINERS
---------- */
section {
	position: relative;
	padding: 2.5rem 0;
}
.container {
	position: relative;
	margin: auto;
	padding: 0 20px;
	width: 100%;
	max-width: 970px;
}
section:after, .container:after, .row:after {
	display: table;
	content: '';
	clear: both;
}


/* ----------
	ANHOR TAG
---------- */
a {
	cursor: pointer;
	outline: 0;
}
h1 > a,
h2 > a,
h3 > a,
h4 > a,
h5 > a,
h6 > a,
p  > a {
	color: #ed9d0a;
	text-decoration: none;
}
h1 > a:hover,
h2 > a:hover,
h3 > a:hover,
h4 > a:hover,
h5 > a:hover,
h6 > a:hover,
p  > a:hover,
ul a:hover {
	text-decoration: underline;
}


/* ----------
	TYPOGRAPHY
---------- */
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
ul {
	margin-bottom: 1rem;
	-ms-word-break: break-word;
	-ms-word-wrap: break-word;
	-webkit-word-break: break-word;
	-webkit-word-wrap: break-word;
	word-break: break-word;
	word-wrap: break-word;
}
h1:last-child,
h2:last-child,
h3:last-child,
h4:last-child,
h5:last-child,
h6:last-child,
p:last-child,
blockquote:last-child,
ul:last-child {
	margin-bottom: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
	line-height: 1.25em;
	letter-spacing: 1px;
	font-weight: 600;
}
h1:not(:first-child),
h2:not(:first-child),
h3:not(:first-child),
h4:not(:first-child),
h5:not(:first-child),
h6:not(:first-child) {
	margin-top: 1.5em;
}
h1 {
	letter-spacing: 2px;
	font-size: 1.75rem;
}
h2 {
	font-size: 1.5rem;
}
h1 strong,
h2 strong,
h3 strong,
h4 strong,
h5 strong,
h6 strong {
	font-weight: 700;
}
p {
	line-height: 1.5em;
}
ul {
	padding-left: 1.5rem;
}
hr {
	border: 0;
	border-top: 1px solid #e1e1e1;
}


/* ----------
	CODE BLOCK
---------- */
.code-container {
	position: relative;
	margin-bottom: 1.5rem;
	overflow: hidden;
	border-radius: 3px;
	box-shadow: 3px 3px 6px rgba(0, 0, 0, .3);
}
.code-container:last-child {
	margin-bottom: 0;
}

.btn {
	background-color: #ed9d0a;
	color: #fff;
	padding: 4px 10px;
	text-decoration: none;
	border-radius: 3px;
	box-shadow: 0 8px 6px -6px rgba(0, 0, 0, .15);
	-webkit-backface-visibility: hidden;
	-webkit-transition: 200ms -webkit-transform ease, 200ms transform ease, 200ms box-shadow ease;
			transition: 200ms -webkit-transform ease, 200ms transform ease, 200ms box-shadow ease;
}
.btn:hover {
	box-shadow: 0 6px 6px -4px rgba(0, 0, 0, .2);
	-webkit-transform: translateY(-2px);
			transform: translateY(-2px);
}
.btn.btn-left {
	float: left;
}
.btn.btn-right {
	float: right;
}


.row {
	margin-bottom: 1.5rem;
	width: 100%;
}
.row:last-child {
	margin-bottom: 0;
}
              
            
!

JS

              
                /**
 * 
 * In this pen:
 * added scripts with CDN:
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/codemirror.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/mode/xml/xml.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/mode/css/css.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/mode/javascript/javascript.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/mode/htmlmixed/htmlmixed.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/addon/edit/closebrackets.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/addon/fold/xml-fold.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/addon/edit/closetags.js
 *   -  //cdnjs.cloudflare.com/ajax/libs/codemirror/5.13.4/addon/comment/comment.js 
 * 
 */

// adding the ../addon/comment/comment.js addon will
// allow comments with the shortcut: Ctrl+/ 

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
	lineNumbers: true,			// gives a lineNumber gutter
	mode: 'htmlmixed',			// sets syntax mode
	theme: 'material',			// select theme
	
	indentUnit: 4,				// default is 2
	tabSize: 4,					// default already is 4
	indentWithTabs: true,		// default is false
	
	fixedGutter: true,
	coverGutterNextToScrollbar: true,
	
	showCursorWhenSelecting: true,
	
	allowDropFileTypes: ['.htm', '.html', '.htmls', '.htt', '.htx', 'shtml'],
	
	electricChars: true,		// Configures whether the editor should re-indent the current line
								// when a character is typed that might change its proper indentation
								//(only works if the mode supports indentation). Default is true.
	
	keyMap: 'sublime',			// uses Sublime Text keymapping
								// down at the bottom of this script you can see the key commands
								// please note that I added this script: ../keymap/sublime.js
	
	autoCloseBrackets: true,	// typed characters like ()[]{}''"" don't close automatically,
								// please note that I added this script: ../addon/edit/closebrackets.js
								// now type ( [ { ' or " in the editor
	
	autoCloseTags: true,		// tags in html/xml don't close automatically,
								// please note that I added these scripts: ../addon/fold/xml-fold.js
								//										   ../addon/edit/closetag.js
								// now type <div> in the editor
});

/**
 *
 * Sublime Text keyMap
 *
 * not all functions will be available,
 * since some functions depend on other addon scripts
 *
 *
 * key bindings:
 *
 * Alt-Left: 				"goSubwordLeft",
 * Alt-Right: 				"goSubwordRight",
 * Ctrl-Up: 				"scrollLineUp",
 * Ctrl-Down: 				"scrollLineDown",
 * Shift-Ctrl-L: 			"splitSelectionByLine",
 * Shift-Tab: 				"indentLess",
 * Esc: 					"singleSelectionTop",
 * Ctrl-L: 					"selectLine",
 * Shift-Ctrl-K: 			"deleteLine",
 * Ctrl-Enter: 				"insertLineAfter",
 * Shift-Ctrl-Enter: 		"insertLineBefore",
 * Ctrl-D: 					"selectNextOccurrence",
 * Alt-CtrlUp: 				"addCursorToPrevLine",
 * Alt-CtrlDown: 			"addCursorToNextLine",
 * Shift-Ctrl-Space:		"selectScope",
 * Shift-Ctrl-M: 			"selectBetweenBrackets",
 * Ctrl-M: 					"goToBracket",
 * Shift-Ctrl-Up: 			"swapLineUp",
 * Shift-Ctrl-Down: 		"swapLineDown",
 * Ctrl-/: 					"toggleCommentIndented",
 * Ctrl-J:		 			"joinLines",
 * Shift-Ctrl-D: 			"duplicateLine",
 * Ctrl-T: 					"transposeChars",
 * F9: 						"sortLines",
 * Ctrl-F9: 				"sortLinesInsensitive",
 * F2: 						"nextBookmark",
 * Shift-F2: 				"prevBookmark",
 * Ctrl-F2: 				"toggleBookmark",
 * Shift-Ctrl-F2: 			"clearBookmarks",
 * Alt-F2: 					"selectBookmarks",
 * Alt-Q: 					"wrapLines",
 * Ctrl-K Ctrl-Backspace: 	"delLineLeft",
 * Backspace: 				"smartBackspace",
 * Ctrl-K Ctrl-K: 			"delLineRight",
 * Ctrl-K Ctrl-U: 			"upcaseAtCursor",
 * Ctrl-K Ctrl-L: 			"downcaseAtCursor",
 * Ctrl-K Ctrl-Space: 		"setSublimeMark",
 * Ctrl-K Ctrl-A: 			"selectToSublimeMark",
 * Ctrl-K Ctrl-W: 			"deleteToSublimeMark",
 * Ctrl-K Ctrl-X: 			"swapWithSublimeMark",
 * Ctrl-K Ctrl-Y: 			"sublimeYank",
 * Ctrl-K Ctrl-G: 			"clearBookmarks",
 * Ctrl-K Ctrl-C: 			"showInCenter",
 * Ctrl-Alt-Up: 			"selectLinesUpward",
 * Ctrl-Alt-Down: 			"selectLinesDownward",
 * Ctrl-F3: 				"findUnder",
 * Shift-Ctrl-F3: 			"findUnderPrevious",
 * Shift-Ctrl-[: 			"fold",
 * Shift-Ctrl-]: 			"unfold",
 * Ctrl-K Ctrl-J: 			"unfoldAll",
 * Ctrl-K Ctrl-0: 			"unfoldAll",
 * Ctrl-H: 					"replace",
 *
 */
              
            
!
999px

Console