cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container" ng-app="myApp" ng-controller="Example">
	<div class="jumbotron">
		<div class="container">
			<h2>execCommands supported in your browser</h2>
      <div class="row">
        <div class="col-md-6">The <small class="btn btn-success btn-xs">Green</small> commands are supported by your browser, where as the <small class="btn btn-error btn-xs">Grey</small> ones.. You guessed it! :-) <br />Anyway try to select contents below and click <small class="btn btn-success btn-xs">commands</small> to execute the commands on it. <br />I use the HTML attribute <code>contenteditable=true</code> to allow modifications to the content. <code>Updated</code>: Added <a href="https://fortawesome.github.io/Font-Awesome/icons/">font awesome icons</a>. <br /> <br />Inspired by <a href="https://css-tricks.com/cut-and-copy-from-javascript/">Cut and Copy (from JavaScript)</a></div>
        <div class="col-md-6"><strong>From</strong> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand">developer.mozilla.org</a>:<br /><small>			Summary of the command <code>Document.execCommand()</code></small><br />
        <em>When an HTML document has been switched to designMode, the document object exposes the execCommand method which allows one to run commands to manipulate the contents of the editable region. Most commands affect the document's selection (bold, italics, etc), while others insert new elements (adding a link) or affect an entire line (indenting). When using contentEditable, calling execCommand will affect the currently active editable element.</em></div>
        </div>

			<div class="col-md-12 tags"><strong>Tags:</strong>
				<span ng-repeat="tag in tags">
            <a href="https://codepen.io/search?q={{tag}}&limit=all&depth=everything&show_forks=false"><code class="btn btn-primary btn-xs">{{tag}}</code></a></span>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
						<div class="col-md-12 tags">
				<span ng-repeat="cmd in commands">
            <code class="btn btn-xs" title="{{cmd.desc}}" ng-class="supported(cmd)" ng-click="doCommand(cmd)"><i ng-class="icon(cmd)"></i> {{cmd.cmd}}</code></span>
			</div>
			</div>
    <div class="row" contentEditable="true">
      <div class="col-md-3"> <br /><br />From <a href="https://www.picksumipsum.co.uk/">www.picksumipsum.co.uk</a>
        <img src="https://www.picksumipsum.co.uk/wp-content/themes/starkers/images/e.png" alt="" class="img-responsive" /><h4>CLINT EASTWOOD</h4></div>
      <div class="col-md-9">
        
        <div class="row" contentEditable="true">
          <div class="col-md-12">
            <h3>Try to alter this text using the execCommands buttons above</h3>
            You see, in this world there's two kinds of people, my friend: those with loaded guns and those who dig. you dig. well, do you have anything to say for yourself? you see, in this world there's two kinds of people, my friend: those with loaded guns and those who dig. you dig. <code>don't p!ss down my back and tell me it's raining</code>. dyin' ain't much of a livin', boy. are you feeling lucky punk this is the ak-47 assault rifle, the preferred weapon of your enemy; and <u>it makes a distinctive sound</u> when fired at you, so remember it. when a naked man's chasing a woman through an alley with a butcher knife and a hard-on, i figure he's not out collecting for the red cross. man's gotta know his limitations. ever notice how sometimes you come across somebody you shouldn't have <a href="https://google.com?q=f**ked" target="_blank" title="Try to ”unlink“ this link.">f**ked</a> with? well, i'm that guy. you see, in this world there's two kinds of people, my friend: those with loaded guns and those who dig. you dig. man's gotta know his limitations. <br /><br /></div>
          
          <div class="col-md-4">You see, in this world there's two kinds of people, my friend: those with loaded guns and those who dig. you dig. well, do you have anything to say for yourself? you want a guarantee, buy a toaster. You want a guarantee, buy a toaster. don't p!ss down my back and tell me it's raining. This is the <b>ak-47</b> assault rifle, the preferred weapon of your enemy; and it makes a <u>distinctive sound</u> when fired at you, <br /><br /></div>
          <div class="col-md-4"><img src="http://dummyimage.com/300x220?text=From%20dummyimage.com" alt="" class="img-responsive" /></div>
          <div class="col-md-4">&#8230;so remember it. dyin' ain't much of a livin', boy. ever notice how sometimes you come across somebody you shouldn't have f**ked with? well, i'm that guy. what you have to ask yourself is, do i feel lucky. well do ya' punk? man's gotta know his limitations. are you feeling lucky punk dyin' ain't much of a livin', boy.</div>
        </div>
<div class="row" contentEditable="true">
  <div class="col-md-12">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod neque eaque fuga culpa doloribus adipisci vel explicabo! Nihil ipsa commodi quae voluptates laudantium fugit nam. Itaque veniam iure aliquid harum!</div>
</div>
      </div>
    </div>
	</div>
</div>


            
          
!
            
                @import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700|Open+Sans:400,800);
body {
font-family: 'Open Sans', sans-serif;
}
.jumbotron {
  padding: 0 0 20px;
  font-family: 'Inconsolata', monospace ;
}
.btn-succes {
  background-color: green;
  color: yellow;
}
.btn-error {
  background-color: grey;
  color: black;
}

.btn-succes, .btn-succes {
  margin: 5px;
}
i {
  color:white;
}
.btn-error i {
  color: black;
}



            
          
!
            
              var parms = [{
	"cmd": "aCommandName",
	"desc": "A DOMString representing the name of the command"
}, {
	"cmd": "aShowDefaultUI",
	"desc": "A Boolean indicating whether the default user interface should be shown. This is not implemented in Mozilla."
}, {
	"cmd": "aValueArgument",
	"desc": "A DOMString representing some commands (such as insertimage) require an extra value argument (the image's url). Pass an argument of null if no argument is needed."
}];
var commands = [{
	"cmd": "backColor",
	"val": "red",
	"desc": "Changes the document background color. In styleWithCss mode, it affects the background color of the containing block instead. This requires a color value string to be passed in as a value argument. (Internet Explorer uses this to set text background color.)"
}, {
	"cmd": "bold",
	"icon": "bold",
	"desc": "Toggles bold on/off for the selection or at the insertion point. (Internet Explorer uses the STRONG tag instead of B.)"
}, {
	"cmd": "contentReadOnly",
	"desc": "Makes the content document either read-only or editable. This requires a boolean true/false to be passed in as a value argument. (Not supported by Internet Explorer.)"
}, {
	"cmd": "copy",
	"icon": "clipboard",
	"desc": "Copies the current selection to the clipboard. Clipboard capability must be enabled in the user.js preference file. See"
}, {
	"cmd": "createLink",
	"val": "https://twitter.com/netsi1964",
	"icon": "link",
	"desc": "Creates an anchor link from the selection, only if there is a selection. This requires the HREF URI string to be passed in as a value argument. The URI must contain at least a single character, which may be a white space. (Internet Explorer will create a link with a null URI value.)"
}, {
	"cmd": "cut",
	"icon": "scissors",
	"desc": "Cuts the current selection and copies it to the clipboard. Clipboard capability must be enabled in the user.js preference file. See"
}, {
	"cmd": "decreaseFontSize",
	"desc": "Adds a SMALL tag around the selection or at the insertion point. (Not supported by Internet Explorer.)"
}, {
	"cmd": "delete",
	"icon": "scissors",
	"desc": "Deletes the current selection."
}, {
	"cmd": "enableInlineTableEditing",
	"desc": "Enables or disables the table row and column insertion and deletion controls. (Not supported by Internet Explorer.)"
}, {
	"cmd": "enableObjectResizing",
	"desc": "Enables or disables the resize handles on images and other resizable objects. (Not supported by Internet Explorer.)"
}, {
	"cmd": "fontName",
	"val": "'Inconsolata', monospace",
	"desc": "Changes the font name for the selection or at the insertion point. This requires a font name string (\"Arial\" for example) to be passed in as a value argument."
}, {
	"cmd": "fontSize",
	"val": "1-7",
	"icon": "text-height",
	"desc": "Changes the font size for the selection or at the insertion point. This requires an HTML font size (1-7) to be passed in as a value argument."
}, {
	"cmd": "foreColor",
	"val": "rgba(0,0,0,.5)",
	"desc": "Changes a font color for the selection or at the insertion point. This requires a color value string to be passed in as a value argument."
}, {
	"cmd": "formatBlock",
	"desc": "Adds an HTML block-style tag around the line containing the current selection, replacing the block element containing the line if one exists (in Firefox, BLOCKQUOTE is the exception - it will wrap any containing block element). Requires a tag-name string to be passed in as a value argument. Virtually all block style tags can be used (eg. \"H1\", \"P\", \"DL\", \"BLOCKQUOTE\"). (Internet Explorer supports only heading tags H1 - H6, ADDRESS, and PRE, which must also include the tag delimiters < >, such as \"<H1>\".)"
}, {
	"cmd": "forwardDelete",
	"desc": "Deletes the character ahead of the cursor's position.  It is the same as hitting the delete key."
}, {
	"cmd": "heading",
	"val": "h3",
	"icon": "header",
	"desc": "Adds a heading tag around a selection or insertion point line. Requires the tag-name string to be passed in as a value argument (i.e. \"H1\", \"H6\"). (Not supported by Internet Explorer and Safari.)"
}, {
	"cmd": "hiliteColor",
	"val": "Orange",
	"desc": "Changes the background color for the selection or at the insertion point. Requires a color value string to be passed in as a value argument. UseCSS must be turned on for this to function. (Not supported by Internet Explorer.)"
}, {
	"cmd": "increaseFontSize",
	"desc": "Adds a BIG tag around the selection or at the insertion point. (Not supported by Internet Explorer.)"
}, {
	"cmd": "indent",
	"icon": "indent",
	"desc": "Indents the line containing the selection or insertion point. In Firefox, if the selection spans multiple lines at different levels of indentation, only the least indented lines in the selection will be indented."
}, {
	"cmd": "insertBrOnReturn",
	"desc": "Controls whether the Enter key inserts a br tag or splits the current block element into two. (Not supported by Internet Explorer.)"
}, {
	"cmd": "insertHorizontalRule",
	"desc": "Inserts a horizontal rule at the insertion point (deletes selection)."
}, {
	"cmd": "insertHTML",
	"val": "<h3>Life is great!</h3>",
	"icon": "code",
	"desc": "Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string to be passed in as a value argument. (Not supported by Internet Explorer.)"
}, {
	"cmd": "insertImage",
	"val": "http://dummyimage.com/160x90",
	"icon": "picture-o",
	"desc": "Inserts an image at the insertion point (deletes selection). Requires the image SRC URI string to be passed in as a value argument. The URI must contain at least a single character, which may be a white space. (Internet Explorer will create a link with a null URI value.)"
}, {
	"cmd": "insertOrderedList",
	"icon": "list-ol",
	"desc": "Creates a numbered ordered list for the selection or at the insertion point."
}, {
	"cmd": "insertUnorderedList",
	"icon": "list-ul",
	"desc": "Creates a bulleted unordered list for the selection or at the insertion point."
}, {
	"cmd": "insertParagraph",
	"icon": "paragraph",
	"desc": "Inserts a paragraph around the selection or the current line. (Internet Explorer inserts a paragraph at the insertion point and deletes the selection.)"
}, {
	"cmd": "insertText",
	"val": new Date(),
	"icon": "file-text-o",
	"desc": "Inserts the given plain text at the insertion point (deletes selection)."
}, {
	"cmd": "italic",
	"icon": "italic",
	"desc": "Toggles italics on/off for the selection or at the insertion point. (Internet Explorer uses the EM tag instead of I.)"
}, {
	"cmd": "justifyCenter",
	"icon": "align-center",
	"desc": "Centers the selection or insertion point."
}, {
	"cmd": "justifyFull",
	"icon": "align-justify",
	"desc": "Justifies the selection or insertion point."
}, {
	"cmd": "justifyLeft",
	"icon": "align-left",
	"desc": "Justifies the selection or insertion point to the left."
}, {
	"cmd": "justifyRight",
	"icon": "align-right",
	"desc": "Right-justifies the selection or the insertion point."
}, {
	"cmd": "outdent",
	"icon": "outdent",
	"desc": "Outdents the line containing the selection or insertion point."
}, {
	"cmd": "paste",
	"icon": "clipboard",
	"desc": "Pastes the clipboard contents at the insertion point (replaces current selection). Clipboard capability must be enabled in the user.js preference file. See"
}, {
	"cmd": "redo",
	"icon": "repeat",
	"desc": "Redoes the previous undo command."
}, {
	"cmd": "removeFormat",
	"desc": "Removes all formatting from the current selection."
}, {
	"cmd": "selectAll",
	"desc": "Selects all of the content of the editable region."
}, {
	"cmd": "strikeThrough",
	"icon": "strikethrough",
	"desc": "Toggles strikethrough on/off for the selection or at the insertion point."
}, {
	"cmd": "subscript",
	"icon": "subscript",
	"desc": "Toggles subscript on/off for the selection or at the insertion point."
}, {
	"cmd": "superscript",
	"icon": "superscript",
	"desc": "Toggles superscript on/off for the selection or at the insertion point."
}, {
	"cmd": "underline",
	"icon": "underline",
	"desc": "Toggles underline on/off for the selection or at the insertion point."
}, {
	"cmd": "undo",
	"icon": "undo",
	"desc": "Undoes the last executed command."
}, {
	"cmd": "unlink",
	"icon": "chain-broken",
	"desc": "Removes the anchor tag from a selected anchor link."
}, {
	"cmd": "useCSS ",
	"desc": "Toggles the use of HTML tags or CSS for the generated markup. Requires a boolean true/false as a value argument. NOTE: This argument is logically backwards (i.e. use false to use CSS, true to use HTML). (Not supported by Internet Explorer.) This has been deprecated; use the styleWithCSS command instead."
}, {
	"cmd": "styleWithCSS",
	"desc": "Replaces the useCSS command; argument works as expected, i.e. true modifies/generates style attributes in markup, false generates formatting elements."
}];
angular.module("myApp", [])
	.directive("click", function () {
		return {
			restrict: "A",
			link: function (scope, element, attrs) {
				element.bind("click", function () {
					scope.$evalAsync(attrs.click);
				});
			}
		};
	})
	.controller("Example", function ($scope) {
		$scope.supported = function (cmd) {
			var css = !!document.queryCommandSupported(cmd.cmd) ? "btn-succes" : "btn-error"
			return css
		};
		$scope.icon = function (cmd) {
			return (typeof cmd.icon !== "undefined") ? "fa fa-" + cmd.icon : "";
		};
		$scope.doCommand = function (cmd) {
			if ($scope.supported(cmd) === "btn-error") {
				alert("execCommand(“" + cmd.cmd + "”)\nis not supported in your browser");
				return;
			}
			val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "";
			document.execCommand(cmd.cmd, false, (cmd.val || ""));
		}
		$scope.commands = commands;
		$scope.tags = [
    'Bootstrap', 'AngularJS', 'execCommand'
  ]
	})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console