Create Scratch Card using JavaScript & HTML5 Canvas

Yet another code snippet to create scratch card using JavaScript and HTML5 canvas. This Vanilla JavaScript plugin allows you to hide your coupon code or other winning code that will show on scratch. You can place any number/text behind the scratch area. Users can scratch with cursor or touch swipe. Moreover, it shows a real-time scratching animation.

Scratch Card Plugin Overview and Preview

Plugin: scratch-card-with-canvas
Author: Prototype
Category: Others
Published: November 8, 2019
File Type: zip archive (HTML, CSS & JavaScript )
Package Size: 6 KB
Dependencies: No dependency!
Last Modified:

Code Rating

[site_reviews_summary assigned_to=”post_id”]

How to Create JavaScript Scratch Card

1. First of all create HTML canvas element and other necessary elements like below:

    <div class="card">
    <div class="base">Coupon Code: 123456789</div>
    <canvas id="scratch" width="300" height="60"></canvas>

2. After that, style scratch card with CSS.

         width: 300px;
         height: 60px;
         position: relative;
         box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.2);
      .base, #scratch {
        cursor: default;
        height: 60px;
        width: 300px;
          position: absolute;
          top: 0;
          left: 0;
          cursor: grabbing;
      .base {
        line-height: 60px;
        text-align: center;
      #scratch {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 
        -webkit-touch-callout: none;
        -webkit-user-select: none;

3. Finally, load the scratch card JS file into your HTML document and done.

<!-- scratch-card-with-canvas JS -->
<script src="js/scratch-card.js"></script>


No data yet!

No Configuration Options!
[site_reviews assigned_to=”post_id”]

Submit Your Review

[site_reviews_form assign_to=”post_id”]