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

              
                <h1>How does stroke-dasharray work</h1>
<p>stroke-dasharray only works on SVG elements. It is a bit confusing because you can apply it using CSS, but that CSS rule will only affect SVG elements.</p>
<p>Let's make an svg box that is 100 by 100 so 400 length perimeter, and apply <pre>
  stroke-dasharray: 10;
</pre></p>

	<svg width="100" height="100" class="strokeTest">
		<rect width="100" height="100" x="0" y="0" />
	</svg>

<p></p>

<a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray">If you read the docs</a> stroke-dasharray: "specify the lengths of alternating dashes and gaps. If an odd number of values is provided, then the list of values is repeated to yield an even number of values.</p>

<p>So a pair of numbers specifics the length of a dash, and a gap. This then gets repeated all the way around the shape.</p>

<p>Important, these lengths are relative to the SVG, viewports can change this etc</p>

<p>Play with the CSS. Notice that 
<pre>
  stroke-dasharray: 10;
</pre>
  and
<pre>
  stroke-dasharray: 10 10;
</pre>
are the same effect because if you have an odd number of lengths, they get doubled.
</p>

<p>You could set a specific length for each dash and gap around a whole shape if you wanted to.</p>

<p>Let's make a second shape and give it increasingly larger dashes, and gaps using
  <pre>
stroke-dasharray: 10 20 30 40 50 60;
</pre>
</p>

	<svg width="100" height="100" class="strokeTestExtended">
		<rect width="100" height="100" x="0" y="0" />
	</svg>

<p>Notice how the pattern wraps around and hits the end before it can finish the second time. This is becase 10+20+30+40+50+60 = 210, while the perimeter of the square is only 400, so the last 20 is cut off.</p>

<!-- twitter -->
<a class="twitter" target="_top" href="https://twitter.com/joshdance">  <svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" viewBox="0 0 72 72"><path d="M67.812 16.141a26.246 26.246 0 0 1-7.519 2.06 13.134 13.134 0 0 0 5.756-7.244 26.127 26.127 0 0 1-8.313 3.176A13.075 13.075 0 0 0 48.182 10c-7.229 0-13.092 5.861-13.092 13.093 0 1.026.118 2.021.338 2.981-10.885-.548-20.528-5.757-26.987-13.679a13.048 13.048 0 0 0-1.771 6.581c0 4.542 2.312 8.551 5.824 10.898a13.048 13.048 0 0 1-5.93-1.638c-.002.055-.002.11-.002.162 0 6.345 4.513 11.638 10.504 12.84a13.177 13.177 0 0 1-3.449.457c-.846 0-1.667-.078-2.465-.231 1.667 5.2 6.499 8.986 12.23 9.09a26.276 26.276 0 0 1-16.26 5.606A26.21 26.21 0 0 1 4 55.976a37.036 37.036 0 0 0 20.067 5.882c24.083 0 37.251-19.949 37.251-37.249 0-.566-.014-1.134-.039-1.694a26.597 26.597 0 0 0 6.533-6.774z"></path>
  </svg>
</a>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
}

.strokeTest {
  stroke-width: 3;
  stroke: red;
  overflow: visible;
  width: 100px;
  height: 100px;
  stroke-dasharray: 25;
  stroke-dashoffset: 10;
}

.strokeTestExtended {
  stroke-width: 3;
  stroke: red;
  overflow: visible;
  width: 100px;
  height: 100px;
  stroke-dasharray: 10 20 30 40 50 60;
}


/* csss for twitter icon in corner */
.twitter {
  position: fixed;
  display: block;
  right: 12px;
  bottom: 12px;
}

.twitter svg {
  width: 32px;
  height: 32px;
  fill: rgb(66, 239, 255);
  border: none;
}
              
            
!

JS

              
                
              
            
!
999px

Console