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 class="container">
	<h1>Safe Regex new line</h1>
	<textarea
		id="regexTextarea"
		class="textarea"
		cols="100"
		rows="6"
	></textarea>
	<p id="regexTextareaVal" class="textareaVal"></p>
</div>

<div class="container">
	<h1>Safe Pre new line</h1>
	<p>
			Note that the pre element has
			<span class="code">white-space: pre-line;</span>
			defined with CSS
	</p>
	<textarea
		id="preTextarea"
		class="textarea"
		cols="100"
		rows="6"
	></textarea>
	<pre id="preTextareaVal" class="textareaVal"></pre>
</div>

              
            
!

CSS

              
                *,
*::after,
*::before {
	box-sizing: border-box;
}

body,
textarea {
	font-family: 'Open Sans', sans-serif;
	line-height: 1.2em;
}

h1 {
	font-size: 1.25em;
	margin-bottom: 0.3em;
}

pre {
	white-space: pre-line;
}

.code {
	font-family: "Monaco", "Consolas", "Lucida Console", monospace;
	display: inline-block;
	padding: 0 0.375em;
	color: gray;
	background-color: #e6e6e6;
	border-radius: 2px;
}

.container {
	overflow: hidden;
	padding: 0 16px;
	max-width: 600px;
	margin: 15px auto 0;
}

.textarea,
.textareaVal {
	margin-bottom: 15px;
}

.textarea {
	padding: 0.8em;
	font-size: 1em;
	width: 100%;
}

.textareaVal {
	color: gray;
}

              
            
!

JS

              
                /**
 * Replaces string new lines with `<br>`
 * @see {@link https://stackoverflow.com/q/863779/3841699}
 * @see {@link https://stackoverflow.com/a/1761086/3841699}
 * @type {string} str
 * @type {HTMLElement} elem
 */
function breakText(str, elem) {
	var newLineRegex = /(\n|\n|\r)/gm
	return str
		.split(newLineRegex)
		.forEach(function(part) {
			if (part.match(newLineRegex)) {
				var br = document.createElement('br')
				elem.appendChild(br)
			} else {
				elem.innerText += part
			}
		})
}

// Regex safe new line
////////////////////////////////////////////////////////////////////////////////
var regexTextArea = document.getElementById('regexTextarea')
var regexTextareaVal = document.getElementById('regexTextareaVal')

regexTextArea.addEventListener('input', function(e) {
	regexTextareaVal.innerText = ''
	breakText(regexTextArea.value, regexTextareaVal)
})

// Pre safe new line
////////////////////////////////////////////////////////////////////////////////
var preTextarea = document.getElementById('preTextarea')
var preTextareaVal = document.getElementById('preTextareaVal')

preTextarea.addEventListener('input', function(e) {
	preTextareaVal.innerText = preTextarea.value
})

              
            
!
999px

Console