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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1>funky canvas coat for a wallflower checkbox</h1>
	<canvas id="myCanvas" width="94" height="27"><input type="checkbox" id="check0" title="on/off"></canvas>

<h2>notes:</h2>
	<ul>
	  <li>uses standard HTML checkbox</li>
	  <li>keyboard operable</li>
	  <li>role/name/state/properies and interaction exposed to acc layer without need for ARIA or custom keyboard Jazz.</li>
    <li>No JavaScript? no canvas support? no problem, defaults to standard checkbox (Except in IE - <a href="https://connect.microsoft.com/IE/feedback/details/1133285/when-javascript-disabled-canvas-sub-dom-content-not-displayed">bug filed</a>)</li>
</ul>

<h2>HTML code:</h2>
<pre>
&lt;canvas id=&quot;myCanvas&quot; width=&quot;94&quot; height=&quot;27&quot;&gt;
&lt;input type=&quot;checkbox&quot; id=&quot;check0&quot; title=&quot;on/off&quot;&gt;
&lt;/canvas&gt;
    </pre>
            
          
!
            
              body {font-family:sans-serif;}




            
          
!
            
              var canvas = document.getElementById('myCanvas');
		var checkbox = document.getElementById('check0') ;
		var context = canvas.getContext('2d');
		var imageObj = new Image();
		var noCheckedUpdate = false;

		imageObj.onload = function() {
			context.drawImage(imageObj, 0, 0);
		};
		imageObj.src = 'http://www.html5accessibility.com/images/off.png';
		canvas.addEventListener("click", doClick, false);
		checkbox.addEventListener("change", doChange, false);
		checkbox.addEventListener("focus", doFocus, false);
		checkbox.addEventListener("blur", doBlur, false);

		function doClick() {
			toggleImg(noCheckedUpdate ? checkbox.checked : !checkbox.checked);
    }

		function doChange(event) {
			noCheckedUpdate = true;
			toggleImg(event.target.checked, true);		
		}

		function toggleImg(turnOn, leaveCheckedAlone) {
			imageObj.src = turnOn ? 'http://www.html5accessibility.com/images/on.png' : 'http://www.html5accessibility.com/images/off.png'; 
			if (!noCheckedUpdate) {
				checkbox.checked = turnOn;
				noCheckedUpdate = false;
			}
		}

		function doFocus(event) {  
			canvas.style.outline='solid #8080FF medium';
		}

		function doBlur() {	
			canvas.style.outline='solid #fff medium';
		}
            
          
!
999px

Console