javascriptcodepen

Generate Code pen link programmatically - Javascript


I would like to generate code pen link with pre-filled css data.

How can I do it programmatically in javascript?

I tried posting the pre-filled data to code pen but not able to generate codepen link programmatically.


Solution

  • You should use CodePen API for that.

    Example:

    <form action="https://codepen.io/pen/define" method="POST" target="_blank">
      <input type="hidden" name="data" value='{"title": "New Pen!", "html": "<div>Hello, World!</div>"}'>
    
      <input type="submit" value="Create New Pen with Prefilled Data">
    </form>
    

    More info: