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

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

              
                <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" class="filterwrapper">
        <defs>
            <svg id="glitchmask-r" width="100%" height="100%" viewbox="0 0 100 100" preserveAspectRatio="none">
                <line class="top-r" x1="0" y1="0" x2="100%" y2="0"> </line>
                <line class="bot-r" x1="0" y1="100%" x2="100%" y2="100%"></line>
            </svg>
            <svg id="glitchmask-g" width="100%" height="100%" viewbox="0 0 100 100" preserveAspectRatio="none">
                <line class="top-g" x1="0" y1="0" x2="100%" y2="0"></line>
                <line class="bot-g" x1="0" y1="100%" x2="100%" y2="100%"></line>
            </svg>

            <filter color-interpolation-filters="sRGB" id="filter" width="100%" heigth="100%" x="0" y="0">
                <feFlood flood-color="black" result="black" />

                <!-- red text start -->
                <feFlood flood-color="red" result="REDTXT_FLOOD_10" />
                <feComposite operator="in" in="REDTXT_FLOOD_10" in2="SourceAlpha" result="REDTXT_COMP_20" />
                <feOffset in="SourceGraphic" dx="-2" dy="0" result="REDTXT_OFFSET_30" />
                <feMerge result="REDTXT_MERGE_40">
                    <feMergeNode in="black" />
                    <feMergeNode in="REDTXT_COMP_20" />
                    <feMergeNode in="REDTXT_OFFSET_30" />
                </feMerge>
                <feImage preserveAspectRatio="none" id="mask-r" result="REDTXT_IMG_50" xlink:href="#glitchmask-r" />
                <feComposite in2="REDTXT_IMG_50" in="REDTXT_MERGE_40" operator="out" result="REDTXT_COMP_60" />
                <!-- red text end -->

                <!-- green text start -->
                <feFlood flood-color="limegreen" result="GREENTXT_FLOOD_10" />
                <feComposite operator="in" in="GREENTXT_FLOOD_10" in2="SourceAlpha" result="GREENTXT_COMP_20" />
                <feOffset in="SourceGraphic" dx="2" dy="0" result="GREENTXT_OFFSET_30" />
                <feMerge result="GREENTXT_MERGE_40">
                    <feMergeNode in="black" />
                    <feMergeNode in="GREENTXT_COMP_20" />
                    <feMergeNode in="GREENTXT_OFFSET_30" />
                </feMerge>
                <feImage preserveAspectRatio="none" id="mask-g" result="GREENTXT_IMG_50" xlink:href="#glitchmask-g" />
                <feComposite in2="GREENTXT_IMG_50" in="GREENTXT_MERGE_40" operator="out" result="GREENTXT_COMP_60" />
                <!-- green text end -->

                <feMerge result="MERGE_10">
                    <feMergeNode in="SourceGraphic" />
                    <feMergeNode in="REDTXT_COMP_60" />
                    <feMergeNode in="GREENTXT_COMP_60" />
                </feMerge>
            </filter>
        </defs>
    </svg>
<p class="intro">A cross-browser rework of the popular <a href="https://css-tricks.com/glitch-effect-text-images-svg/" />"Glitch"</a> effect with a CSS animated SVG Filter. It is self-contained and works without duplicating text in pseudo elements. No Javascript needed, except a Firefox bugfix. Create all kinds of variants by playing with CSS and filter values.</p>
<hr/>
<figure class="glitch-filter-example">
  <figcaption class="glitch-filter-example__heading">SVG "Glitch" filter applied to text inside an SVG</figcaption>
  <svg class="glitch-filter-example__demo" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%">
        <text class="glitch-filter-example__filtered-text" y="50%" text-anchor="middle" x="50%" transform="translate(0 34)">SVG text</text>
    </svg>
  </figure>
<hr/>
<figure class="glitch-filter-example">
  <figcaption class="glitch-filter-example__heading">SVG "Glitch" filter applied to HTML text (doesn't work in Safari and IE/Edge)</figcaption>
  <p class="glitch-filter-example__filtered-text">HTML text</p>
  </figure>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Share+Tech+Mono);
html {
    height: 100%;
}

body {
    height: 100%;
    background: black;
    margin: 0;
    padding: 3em;
    font: .8em/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
    color: white;
}

a {
  color: white;
  
  &:hover {
    color: limegreen;
  }
}

.filterwrapper {
    position: absolute;
    z-index: -1;
    pointer-events: none;
    opacity: 0;
}

.svgtext {
    display: block;
    position: relative;
    overflow: hidden;
    margin: 0 auto;
}

.intro {
    margin-bottom: 3em;
}

hr {
    height: 0;
    border-bottom: solid #cccccc 1px;
}

.glitch-filter-example {
    display: block;
    position: relative;
    text-align: center;
    margin: 0;
    padding: 4em 0 2em;
    min-width: 490px;
}

.glitch-filter-example__heading {
    margin: 0;
    margin-bottom: 1em;
    padding: 0;
    display: block;
    position: relative;
}

.glitch-filter-example__filtered-text {
    filter: url(#filter);
    fill: white;
    font-family: 'Share Tech Mono', sans-serif;
    font-size: 100px;
    text-align: center;
    margin: 0;
    padding: 0;
    display: block;
}

.top-r,
.bot-r,
.top-g,
.bot-g {
    stroke: #ffffff;
}

.top-r {
    stroke-width: 100px;
    animation: topani 3.5s linear infinite;
}

.bot-r {
    stroke-width: 100px;
    animation: botani 4s linear infinite;
}

.top-g {
    stroke-width: 50px;
    animation: topani 4s linear reverse infinite;
}

.bot-g {
    stroke-width: 50%;
    animation: botani 3.5s linear reverse infinite;
}

@mixin createRandomKeyframes( $numberOfKeys ) {
    $delta: round(100/$numberOfKeys);
    
    @for $i from 1 through $numberOfKeys {
        $time: ($i*$delta - random($delta)) +'%';
        #{$time} {
            stroke-width: random(200) + px;
        }
    }
}

@keyframes topani {
    @include createRandomKeyframes( 10 + random(10) );
}

@keyframes botani {
    @include createRandomKeyframes( 10 + random(10) );
}
              
            
!

JS

              
                /*
* FIXING A FIREFOX ONLY BROWSERBUG.
* Because of an still unfixed bug, Firefox only can handle xlinks to SVG fragments as URL encoded DataURIs.
* This script fixes this by finding and URLencoding all inline fragments within an SVG.
*/

(function(){
	var ua = navigator.userAgent;

	if(!/firefox/gi.test(ua)){return;}
	// Browsersniffing. Yes, I'm lazy.

	var fragmentID;
	var feImgs = document.querySelectorAll("feImage");
	var cssList = document.styleSheets;
	var cssAnimations = {};

	for (var i = 0; i < cssList.length; i++){
		var css = cssList[i];

		for (var j = 0; j < css.cssRules.length; j++){
			var rule = css.cssRules[j];

			//is rule a keyframe animation?
			if (rule.type === 7){
				cssAnimations[rule.name] = rule.cssText;
			}
		}
	}
			
	for (var i=0, j=feImgs.length; i<j; i++) {
		fragmentID = feImgs[i].getAttribute("xlink:href") || feImgs[i].getAttribute("xlink");

		if(/#/.test(fragmentID) && !/data\:image\/svg\+xml/.test(fragmentID)){
			fragmentAsURIintoFilter(fragmentID, feImgs[i]);
		};
	}

	function fragmentAsURIintoFilter(identifier, fePrimitive){
		var el = document.querySelector(identifier);
		var styledEl = inlineStyles(el);
		var nsAttr = "http://www.w3.org/2000/svg";
		if ( !styledEl.getAttribute("xmlns" )){
			styledEl.setAttribute("xmlns", nsAttr);
		}
        var text = encodeURIComponent(styledEl.outerHTML.replace(/100%/g, "256")).replace("\"", "\'");
		var target = fePrimitive;

		target.setAttribute("xlink:href", "data:image/svg+xml;charset=utf-8," + text);
	}

	// When URLencoded, global styles will no longer apply to the SVG Fragment. So we must inline every rule before:
	function inlineStyles (element) {
		var children = element.querySelectorAll("*");
		var animations = [];

		[].forEach.call(children, function(child){
			var style = getComputedStyle(child);
			child.cssText = style;

			// Look for animations:
			for (var i = 0; i < style.length; i++) {
				var prop = style.item(i);
				var rule = style.getPropertyValue(prop);

				// is there a CSS keyframe animation applied to this element?
				// Copy it to an inlined style.
				if( /animation\-name/.test(prop) && rule !=="none") {
					if(animations.toString().indexOf(rule) < 0) {
						var svgStyle = document.createElement( 'style' );

						svgStyle.innerHTML = cssAnimations[rule];
						element.appendChild(svgStyle);
						animations.push(rule);
					}
				}

				child.style[prop] = rule;			
			}
		});

		return element;
	}
})();
              
            
!
999px

Console