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="editor-holder">
	<ul class="toolbar">
		<li><a href="#" id="indent" title="Toggle tabs or spaces"><i class="fa fa-indent"></i></a></li>
		<li><a href="#" id="fullscreen" title="Toggle fullscreen mode"><i class="fa fa-expand"></i></a></li>
	</ul>
	<div class="scroller">
		<textarea class="editor allow-tabs">&lt;div class="Editable Textarea"&gt;
  &lt;h1&gt;This is a fully editable textarea which auto highlights syntax.&lt;/h1&gt;
  &lt;p&gt;Type or paste any code in here...&lt;/p&gt;
&lt;div&gt;

&lt;?php
  var simple = "coding";
?&gt;

&lt;script&gt;
  with = "Tab or double space functionality";
&lt;/script&gt;</textarea>
		<pre><code class="syntax-highight html"></code></pre>
	</div>
</div>

              
            
!

CSS

              
                html, body{
	margin: 0;
	padding: 0;
	height: 100%;
	width: 100%;
	position: relative;
	background: rgb(114, 195, 195);
}

.editor-holder{
	width: 800px;
	height: 500px;
	margin-top: 50px;
	border-radius: 3px;
	position: relative;
	top: 0;
	margin-left: -400px;
	left: 50%;
	background: #1f1f1f !important;
	overflow: auto;
	box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.4);
	transition: all 0.5s ease-in-out;
	
	&.fullscreen{
		width: 100%;
		height: 100%;
		margin: 0;
		left: 0;
	}
	
	.toolbar{
		width: 100%;
		list-style: none;
		position: absolute;
		top: -2px;
		margin: 0;
		left: 0;
		z-index: 3;
		padding: 8px;
		background: #afafaf;
		li{
			display: inline-block;
		}
		a{
			line-height: 20px;
			background: rgba(144, 144, 144, 0.6);
			color: grey;
			box-shadow: inset -1px -1px 1px 0px rgba(0,0,0,0.28);
			display: block;
			border-radius: 3px;
			cursor: pointer;
			&:hover{
				background: rgba(144, 144, 144, 0.8);
			}
			&.active{
				background: rgba(144, 144, 144, 0.8);
				box-shadow: none;
			}
		}
		i{
			color: #565656;
			padding: 8px;
		}
	}
	
	textarea, code{
		width: 100%;
		height: auto;
		min-height: 450px;
		font-size: 14px;
		border: 0;
		margin: 0;
		top: 46px;
		left: 0;
		padding: 20px !important;
		line-height: 21px;
		position: absolute;
		font-family: Consolas,Liberation Mono,Courier,monospace;
		overflow: visible;
		transition: all 0.5s ease-in-out;
	}
	
	textarea{
		background: transparent !important;
		z-index: 2;
		height: auto;
		resize: none;
		color: #fff;
    text-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
    text-fill-color: transparent;
		-webkit-text-fill-color: transparent;
		
		&::-webkit-input-placeholder{
			color: rgba(255, 255, 255, 1);
		}
		
		&:focus{
			outline: 0;
			border: 0;
			-webkit-box-shadow: none;
			-moz-box-shadow: none;
			box-shadow: none;
		}
	}

	code{
		z-index: 1;
	}
}

pre {
	white-space: pre-wrap;  
	white-space: -moz-pre-wrap;
	white-space: -pre-wrap;  
	white-space: -o-pre-wrap;
	word-wrap: break-word;
	code{
		background: #1f1f1f !important;
		color: #adadad;

		.hljs {
			color: #a9b7c6;
			background: #282b2e;
			display: block;
			overflow-x: auto;
			padding: 0.5em
		}
		.hljs-number,
		.hljs-literal,
		.hljs-symbol,
		.hljs-bullet {
				color: #6897BB
		}
		.hljs-keyword,
		.hljs-selector-tag,
		.hljs-deletion {
				color: #cc7832
		}
		.hljs-variable,
		.hljs-template-variable,
		.hljs-link {
				color: #629755
		}
		.hljs-comment,
		.hljs-quote {
				color: #808080
		}
		.hljs-meta {
				color: #bbb529
		}
		.hljs-string,
		.hljs-attribute,
		.hljs-addition {
				color: #6A8759
		}
		.hljs-section,
		.hljs-title,
		.hljs-type {
				color: #ffc66d
		}
		.hljs-name,
		.hljs-selector-id,
		.hljs-selector-class {
				color: #e8bf6a
		}
		.hljs-emphasis {
				font-style: italic
		}
		.hljs-strong {
				font-weight: bold
		}
	}
}
              
            
!

JS

              
                var tabCharacter = "  ";
var tabOffset = 2;

$(document).on('click', '#indent', function(e){
	e.preventDefault();
	var self = $(this);
	
	self.toggleClass('active');
	
	if(self.hasClass('active'))
	{
		tabCharacter = "\t";
		tabOffset = 1;
	}
	else
	{
		tabCharacter = "  ";
		tabOffset = 2;
	}
})

$(document).on('click', '#fullscreen', function(e){
	e.preventDefault();
	var self = $(this);
	
	self.toggleClass('active');
	self.parents('.editor-holder').toggleClass('fullscreen');
});

/*------------------------------------------
	Render existing code
------------------------------------------*/
$(document).on('ready', function(){
	hightlightSyntax();
	
	emmet.require('textarea').setup({
    pretty_break: true,
    use_tab: true
	});
});




/*------------------------------------------
	Capture text updates
------------------------------------------*/
$(document).on('ready load keyup keydown change', '.editor', function(){
	correctTextareaHight(this);
	hightlightSyntax();
});


/*------------------------------------------
	Resize textarea based on content  
------------------------------------------*/
function correctTextareaHight(element)
{
  var self = $(element),
      outerHeight = self.outerHeight(),
      innerHeight = self.prop('scrollHeight'),
      borderTop = parseFloat(self.css("borderTopWidth")),
      borderBottom = parseFloat(self.css("borderBottomWidth")),
      combinedScrollHeight = innerHeight + borderTop + borderBottom;
  
  if(outerHeight < combinedScrollHeight )
  {
    self.height(combinedScrollHeight);
  }
}
// function correctTextareaHight(element){
// 	while($(element).outerHeight() < element.scrollHeight + parseFloat($(element).css("borderTopWidth")) + parseFloat($(element).css("borderBottomWidth"))) {
// 		$(element).height($(element).height()+1);
// 	};
// }


/*------------------------------------------
	Run syntax hightlighter  
------------------------------------------*/
function hightlightSyntax(){
	var me  = $('.editor');
	var content = me.val();
	var codeHolder = $('code');
	var escaped = escapeHtml(content);
	
	codeHolder.html(escaped);
	
	$('.syntax-highight').each(function(i, block) {
		hljs.highlightBlock(block);
	});
}


/*------------------------------------------
	String html characters
------------------------------------------*/
function escapeHtml(unsafe) {
	return unsafe
			 .replace(/&/g, "&amp;")
			 .replace(/</g, "&lt;")
			 .replace(/>/g, "&gt;")
			 .replace(/"/g, "&quot;")
			 .replace(/'/g, "&#039;");
}


/*------------------------------------------
	Enable tabs in textarea
------------------------------------------*/
$(document).delegate('.allow-tabs', 'keydown', function(e) {
	var keyCode = e.keyCode || e.which;

	if (keyCode == 9) {
		e.preventDefault();
		var start = $(this).get(0).selectionStart;
		var end = $(this).get(0).selectionEnd;

		// set textarea value to: text before caret + tab + text after caret
		$(this).val($(this).val().substring(0, start)
								+ tabCharacter
								+ $(this).val().substring(end));

		// put caret at right position again
		$(this).get(0).selectionStart =
		$(this).get(0).selectionEnd = start + tabOffset;
	}
});

              
            
!
999px

Console