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

              
                <textarea onkeyup = 'getCaretPos(event)' id = 'textarea' rows = '1'></textarea>

              
            
!

CSS

              
                #dummy, #textarea{
	box-sizing: border-box;
    font: 14px/1 monospace;
    border: 1px solid #999;
    white-space: pre-wrap;
    margin: 0;
	overflow: hidden;
    width: 100%;
}
#square{
	background: #4CAF50;
	border-radius: 50%;
	height: 5px;
	position: absolute;
	width: 5px;
}
body{
	width: 200px;
}
              
            
!

JS

              
                const getCaretPos = (e) => {
    
    // Getting the textarea element
    let textarea = document.getElementById('textarea');  

	// Adjusting size of it to prevent scrolling
	textarea.style.height = `${e.target.scrollHeight}px`
    
    // Appending element to the DOM after textarea
    textarea.insertAdjacentHTML('afterend', `<span id = 'dummy'>${textarea.value}</span>`);
    
    // Getting the size of the rectangles inside dummy element
    let rectangles = document.getElementById('dummy').getClientRects();
	let last = rectangles[rectangles.length - 1];

	// Getting coordinates of textarea
	let text = document.getElementById('textarea').getBoundingClientRect();
	    
    // Setting coordinates
    let x = last.x + last.width;
    let y = text.y + text.height - last.height;
	
	// Removing dummy
	dummy.remove();
    
    // Drawing pointer
	drawSquare(x, y);
    
    // Returning variables
    return [x, y];
    
}

const drawSquare = (x, y) => {
	
	// Deleting previous square;
	if(document.getElementById('square')) 
		document.getElementById('square').remove();
	
	// Inserting new one
    textarea.insertAdjacentHTML('afterend', `<div id = 'square'></div>`);
	
	// Modifying position of it
	document.getElementById('square').style.left = `${x}px`;
	document.getElementById('square').style.top  = `${y}px`;
	
}
              
            
!
999px

Console