Pen Settings



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


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


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.


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.


                <div class="header">
  <input type="color" id="color_picker" value="#E23164">
  <img src="" id="logo"/>
  <a id="buy_button" class="btn align-right" href="#">Create Product</a>
<div class="canvas-container">
  <canvas id="drawing_canvas"></canvas>
  <div class="initial-message" id="initial_message">
    <p><b>Draw</b> &#x270E; </p>


                body {
  margin: 0;
  font-family: sans-serif;

.canvas-container {
  position: relative;
  height: calc(100vh - 55px);

.initial-message {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);

.hidden {
  display: none;

canvas {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translate(-50%, 0);
  max-width: 90%;
  max-height: 80%;
  box-shadow: 0 0 4px;

.btn {
  background: #E23164;
  background-color: #E23164;
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 4px;
  font-family: Arial;
  color: #ffffff;
  font-size: 14px;
  padding: 8px 20px 8px 20px;
  text-decoration: none;
  font-weight: 700;

.btn:hover {
  background: #E23164;
  background-color: #E23164;
  text-decoration: none;

.header {
  padding: 0.6em;
  box-shadow: 0 0 4px;
  height: 32px;
  background-color: #002B49;

input {
  margin-top: 3px;

#logo {
  position: fixed;
  top: 6px;
  height: 40px;

.align-right {
  float: right;



                // Define the button and canvas variables
const button = document.getElementById('buy_button');
const canvas = document.getElementById('drawing_canvas');

// Add a click handler to the button
button.addEventListener('click', (e) => {
  // Export the base64 image from the canvas
  const base64_image = canvas.toDataURL();
  // You’ll need to replace the API key below with your one. Get your key inside your Print Clever account. It's ok if the key is in the code as in this context it's a bearer token, and all the endpoint does is use it to return your checkout.
  const apiKey = 'jgnVoJBzlYDD5i7RfLfAKn6e2RjaHPkPUJAyUpVw'; 
  // Set the fields to submit. image_url is the only required field for the API request. If you want, you can set the product name, description and price. You can also change the product type and colours using item_code and colours. To find an up-to-date list of available options for these fields, contact your account manager. 
  const options = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${apiKey}`,
    body: JSON.stringify({
      image_url: base64_image,
      item_code: "RNA1",
      name: "Hello World",
      colours: "White,Black",
      description: "Check out this awesome doodle tee, printed on an cotton t-shirt. Created via the Print Clever API and printed on demand.",
      price: 20.00,
  // Open a new tab, ready to receive the product URL. 
  var newTab ='about:blank', '_blank');
    "<body style='background-color:#ffffff;width:100%;height:100%;margin:0;position:relative;'><img src='' style='position:absolute;top:calc(50% - 100px);left:calc(50% - 100px);'/></body>"

  // Send the API request, and redirect the new tab to the URL that is returned
  fetch('', options)
    .then(response => response.json())
    .then(response => newTab.location.href = response.url)
    .catch(err => console.error(err));

// Canvas. We're now into drawing, which you may find useful. Either way, you can see that whatever we put on the canvas will go on to the tee. You could use this, extend it or swap it out for your app content, text, images or whatever //

const context = canvas.getContext('2d');

let color = '#E23164';

const colorPicker = document.getElementById('color_picker');
colorPicker.addEventListener('input', () => {
  color = colorPicker.value;

canvas.width = 1000;
canvas.height = 1300;

var drawingMode = false;
var lastEvent = null;
var lastSize = 0;
var maxSize = 15;
var minSize = 2;

function drawCircle(x, y, radius, color) {
  context.fillStyle = color;
  const canvasRect = canvas.getBoundingClientRect();
  const canvasScale = canvas.width / canvasRect.width;;
  context.scale(canvasScale, canvasScale);
    x - canvasRect.x,
    y - canvasRect.y,
    radius, 0,
    Math.PI * 2,

function onMouseDown(e) {
  if (e.touches) {
    e = e.touches[0];

  lastEvent = e;
  drawingMode = true;

function onMouseUp() {
  drawingMode = false;

function onMouseMove(e) {
  if (!drawingMode) {
  if (e.touches) {
    e = e.touches[0];
  let size = 1;
  // calculate the distance between the points and scale the size of the new circle based on that distance
  const deltaX = e.pageX - lastEvent.pageX;
  const deltaY = e.pageY - lastEvent.pageY;
  const distanceToLastMousePosition = Math.sqrt(
    (deltaX ** 2) +
    (deltaY ** 2)

  size = Math.max(minSize, Math.min(maxSize, distanceToLastMousePosition / 3));
  if (drawingMode) {
    drawCircle(e.pageX, e.pageY, size, color);
  if (lastSize) {
    const deltaSize = size - lastSize;
    for (let i = 0; i < distanceToLastMousePosition; i += 1) {
      const shift = (i / distanceToLastMousePosition);
      // draw circles between our new mouse position and our previous one, to smooth the line out
        e.pageX - (deltaX * shift),
        e.pageY - (deltaY * shift),
        size - (deltaSize * shift),

  lastEvent = e;
  lastSize = size;

canvas.addEventListener('mousedown', onMouseDown);
canvas.addEventListener('touchstart', onMouseDown);

canvas.addEventListener('mousemove', onMouseMove);
canvas.addEventListener('touchmove', onMouseMove);

window.addEventListener('mouseup', onMouseUp);
window.addEventListener('touchend', onMouseUp);