Copy to Clipboard (Preserves Formatting)

Copy to Clipboard

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A clean boilerplate HTML with CSS">
    <title>Boilerplate Page</title>
    
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        h1 {
            font-size: 2rem;
            margin-bottom: 10px;
        }

        p {
            font-size: 1.1rem;
            margin-bottom: 15px;
        }

        a {
            color: #007bff;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            transition: all 0.3s ease;
        }

        .btn:hover {
            background-color: #0056b3;
        }

        @media (max-width: 600px) {
            .container {
                padding: 15px;
            }

            h1 {
                font-size: 1.8rem;
            }

            p {
                font-size: 1rem;
            }
        }
    </style>
</head>
<body>

    <div class="container">
        <h1>Welcome to My Code</h1>
        <p>Let us get started</p>
        <a href="#" class="btn">Get Started</a>
    </div>

</body>
</html>

Documentation

Step1

Copy and paste the custom code in the </body>.

Step2

Add a wrapper and set the attribute of copy-element="code". Add the code block inside this wrapper.

Step3

Add a button and set an attribute of copy-element="button"

Step4 (Optional)

Add optional attributes of copy-message="My message" and active-class="my-active-class"

How to have multiple instances of this functionality on a page?

To use a second, third, or fourth instance on an attribute add x at the end of the value of the element attribute. "x" must be a unique number. This unique number is how you link elements to instances. For example, button2 and code2 will all be connected to the same instance.