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

              
                <!--  
Copy a vector from Adobe Illustrator and paste it in your editor.

<?xml version="1.0" encoding="UTF-8"?><svg id="a" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 35.9"><polygon points="0 29.5 10.7 5.9 27.7 19.5 42.8 0 68.2 12.1 81.9 4.8 89.6 15.4 100 14.3 84.8 31.3 77.7 18.9 61.6 30.3 46.9 17.6 33.4 35.9 12.3 24.6 0 29.5" stroke-width="0"/></svg>

Grab the path points and place them in the function

"0 29.5 10.7 5.9 27.7 19.5 42.8 0 68.2 12.1 81.9 4.8 89.6 15.4 100 14.3 84.8 31.3 77.7 18.9 61.6 30.3 46.9 17.6 33.4 35.9 12.3 24.6 0 29.5"

yields:

clip-path: polygon(0.0% 29.5%, 10.7% 5.9%, 27.7% 19.5%, 42.8% 0.0%, 68.2% 12.1%, 81.9% 4.8%, 89.6% 15.4%, 100.0% 14.3%, 84.8% 31.3%, 77.7% 18.9%, 61.6% 30.3%, 46.9% 17.6%, 33.4% 35.9%, 12.3% 24.6%, 0.0% 29.5%);
-->

              
            
!

CSS

              
                
              
            
!

JS

              
                //0 29.5 10.7 5.9 27.7 19.5 42.8 0 68.2 12.1 81.9 4.8 89.6 15.4 100 14.3 84.8 31.3 77.7 18.9 61.6 30.3 46.9 17.6 33.4 35.9 12.3 24.6 0 29.5


function convertToClipPathFormat(inputStr) {
    const numbers = inputStr.trim().split(/\s+/);
    
    if (numbers.length % 2 !== 0) {
        throw new Error('Invalid input. Expected even number of coordinates.');
    }

    let clipPathStr = 'clip-path: polygon(';

    for (let i = 0; i < numbers.length; i += 2) {
        const x = parseFloat(numbers[i]).toFixed(1);
        const y = parseFloat(numbers[i + 1]).toFixed(1);
        clipPathStr += `${x}% ${y}%, `;
    }

    clipPathStr = clipPathStr.slice(0, -2) + ');';

    return clipPathStr;
}

// Test
const input = "0 29.5 10.7 5.9 27.7 19.5 42.8 0 68.2 12.1 81.9 4.8 89.6 15.4 100 14.3 84.8 31.3 77.7 18.9 61.6 30.3 46.9 17.6 33.4 35.9 12.3 24.6 0 29.5";
console.log(convertToClipPathFormat(input));

              
            
!
999px

Console