search results:

    • Standard
    • React
    License Free hosting Learn Services Community
    • + D
    • Light
    • Dark
    • System
    logo Tailwind Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Contribute
      • Internationalization guide
    • Integrations
      • Angular
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • React
      • Remix
      • Solid
      • Svelte
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Team
      • Testimonials
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • ResourcesNew
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips
    • Overview
    • API

    Tailwind Clipboard method

    Tailwind CSS Clipboard

    Copy to clipboard feature for the latest Tailwind CSS. Let your users easily copy text or links with one click.

    Required ES init: Clipboard *
    * UMD autoinits are enabled by default. This means that you don't need to initialize the component manually. However if you are using Tailwind Elements ES format then you should pass the required components to the initTE method.

    Basic example

    By adding button with data-te-clipboard-init and data-te-clipboard-target attribute you can easily make your text copyable.

    • HTML
    • javascript
            
                
          <div class="flex">
            <div class="relative mb-3 w-full" data-te-input-wrapper-init>
              <input
                type="text"
                class="peer block min-h-[auto] w-full rounded border-0 bg-transparent px-3 py-[0.32rem] leading-[1.6] outline-none transition-all duration-200 ease-linear focus:placeholder:opacity-100 peer-focus:text-primary data-[te-input-state-active]:placeholder:opacity-100 motion-reduce:transition-none dark:text-neutral-200 dark:placeholder:text-neutral-200 dark:peer-focus:text-primary [&:not([data-te-input-placeholder-active])]:placeholder:opacity-0"
                id="copy-target"
                placeholder="Example label" />
              <label
                for="copy-target"
                class="pointer-events-none absolute left-3 top-0 mb-0 max-w-[90%] origin-[0_0] truncate pt-[0.37rem] leading-[1.6] text-neutral-500 transition-all duration-200 ease-out peer-focus:-translate-y-[0.9rem] peer-focus:scale-[0.8] peer-focus:text-primary peer-data-[te-input-state-active]:-translate-y-[0.9rem] peer-data-[te-input-state-active]:scale-[0.8] motion-reduce:transition-none dark:text-neutral-200 dark:peer-focus:text-primary"
                >Type here text to copy
              </label>
            </div>
            <div>
              <button
                id="copy-button"
                type="button"
                data-te-clipboard-init
                data-te-clipboard-target="#copy-target"
                data-te-ripple-init
                data-te-ripple-color="light"
                class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                Copy
              </button>
            </div>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Clipboard,
            Input,
            Ripple,
            initTE,
          } from "tw-elements";
          
          initTE({ Clipboard, Input, Ripple });
          
            
        

    Hey there 👋 we want to make Tailwind Elements a community-driven project. It's open source and free, and we would like it to stay that way. If you enjoy it, help the project grow by sharing it with your peers. Every share counts, thank you!

    Share via Dev.to Share via Twitter Share via Facebook Share via Pinterest Share via Reddit Share via StumbleUpon Share via Vkontakte Share via Weibo Share via HackerNews Share via Gmail Share via Email

    Copy from element

    There is no difference if element is an input or just div element.

    Here is text to copy!
    • HTML
    • javascript
            
                
          <button
            id="copy-button"
            type="button"
            data-te-clipboard-init
            data-te-clipboard-target="#copy-target-2"
            data-te-ripple-init
            data-te-ripple-color="light"
            class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
            Copy
          </button>
    
          <div id="copy-target-2" class="mt-2">Here is text to copy!</div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Clipboard,
            Ripple,
            initTE,
          } from "tw-elements";
          
          initTE({ Clipboard, Ripple });
          
            
        

    Copy from data attribute

    By adding to target of copying data-te-clipboard-text you can set text to copy instead of text from text content.

    Copy text from data-te-attr despite of text content.
    • HTML
    • javascript
            
                
          <button
            id="copy-button"
            type="button"
            data-te-clipboard-init
            data-te-clipboard-target="#copy-target-3"
            data-te-ripple-init
            data-te-ripple-color="light"
            class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
            Copy
          </button>
    
          <div
            id="copy-target-3"
            data-te-clipboard-text="This text is from data-te-attr!"
            class="mt-2">
            Copy text from data-te-attr despite of text content.
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Clipboard,
            Ripple,
            initTE,
          } from "tw-elements";
          
          initTE({ Clipboard, Ripple });
          
            
        

    Feedback example

    Listen for copy.te.clipboard event to perform actions, such as displaying feedback message to users.

    Text copied!
    • HTML
    • javascript
    • umd
            
                
          <div
            id="container-example"
            class="fixed right-0 top-0 z-[2000] mr-3 mt-[59px] hidden w-1/4 items-center rounded-lg bg-primary-100 px-6 py-4 text-base text-primary-800 data-[te-alert-show]:inline-flex"
            role="alert"
            data-te-alert-init
            data-te-autohide="true"
            data-te-delay="4000">
            Text copied!
          </div>
          <div class="flex w-full">
            <div class="relative mb-3 w-full" data-te-input-wrapper-init>
              <input
                type="text"
                class="peer block min-h-[auto] w-full rounded border-0 bg-transparent px-3 py-[0.32rem] leading-[1.6] outline-none transition-all duration-200 ease-linear focus:placeholder:opacity-100 peer-focus:text-primary data-[te-input-state-active]:placeholder:opacity-100 motion-reduce:transition-none dark:text-neutral-200 dark:placeholder:text-neutral-200 dark:peer-focus:text-primary [&:not([data-te-input-placeholder-active])]:placeholder:opacity-0"
                id="copy-target-4"
                placeholder="Example label" />
              <label
                for="copy-target"
                class="pointer-events-none absolute left-3 top-0 mb-0 max-w-[90%] origin-[0_0] truncate pt-[0.37rem] leading-[1.6] text-neutral-500 transition-all duration-200 ease-out peer-focus:-translate-y-[0.9rem] peer-focus:scale-[0.8] peer-focus:text-primary peer-data-[te-input-state-active]:-translate-y-[0.9rem] peer-data-[te-input-state-active]:scale-[0.8] motion-reduce:transition-none dark:text-neutral-200 dark:peer-focus:text-primary"
                >Type here text to copy
              </label>
            </div>
            <div>
              <button
                id="myExample"
                type="button"
                data-te-clipboard-init
                data-te-clipboard-target="#copy-target-4"
                data-te-ripple-init
                data-te-ripple-color="light"
                class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
                Copy
              </button>
            </div>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Alert,
            Clipboard,
            Input,
            Ripple,
            initTE,
          } from "tw-elements";
          
          initTE({ Alert, Clipboard, Input, Ripple });
    
          const myExample = document.getElementById("myExample");
          const alertInstance = Alert.getInstance(
            document.getElementById("container-example")
          );
    
          myExample.addEventListener("copy.te.clipboard", () => {
            myExample.innerText = "Copied!";
            alertInstance.show();
    
            setTimeout(() => {
              myExample.innerText = "COPY";
            }, 4000);
          });
          
            
        
            
                
          const myExample = document.getElementById("myExample");
          const alertInstance = te.Alert.getInstance(
            document.getElementById("container-example")
          );
    
          myExample.addEventListener("copy.te.clipboard", () => {
            myExample.innerText = "Copied!";
            alertInstance.show();
    
            setTimeout(() => {
              myExample.innerText = "COPY";
            }, 4000);
          });
          
            
        

    Related resources

    Buttons Button group Forms Popovers
    • Basic example
    • Copy from element
    • Copy from data attribute
    • Feedback example
    • Related resources

    Tailwind Clipboard method - API


    Import

    Importing components depends on how your application works. If you intend to use the Tailwind Elements ES format, you must first import the component and then initialize it with the initTE method. If you are going to use the UMD format, just import the tw-elements package.

    • javascript
    • umd
            
                
            import { Clipboard, initTE } from "tw-elements";
            initTE({ Clipboard });
            
            
        
            
                
            import "tw-elements";
            
            
        

    Usage

    Via data attributes

    Simply add data-te-clipboard-init attribute to the button to initialize the clipboard component. For ES format, you must first import and call the initTE method.

    • HTML
            
                
            <button
              id="copy-button"
              type="button"
              data-te-clipboard-init
              data-te-clipboard-target="#copy-target"
              data-te-ripple-init
              data-te-ripple-color="light"
              class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
              Copy
            </button>
            
            
        

    Via JavaScript

    • javascript
    • umd
            
                
            const myClipboard = new Clipboard(document.getElementById('clipboard'), options);
            
            
        
            
                
            const myClipboard = new te.Clipboard(document.getElementById('clipboard'), options)
            
            
        

    Options

    Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-te-, as in data-te-clipboard-target="".

    Name Type Default Description
    clipboardTarget Null / String null Points an element from which you will copy text.

    Methods

    Method Description Example
    dispose Manually deletes an instance of clipboard. myClipboard.dispose()
    getInstance Static method which allows you to get the clipboard instance associated to a DOM element. Clipboard.getInstance(myClipboardEl)
    getOrCreateInstance Static method which returns the clipboard instance associated to a DOM element or create a new one in case it wasn't initialized. Clipboard.getOrCreateInstance(myClipboardEl)
    • javascript
    • umd
            
                
            const myClipboardEl = document.getElementById('myClipboard')
            const clipboard = new Clipboard(myClipboardEl)
            clipboard.dispose()
            
            
        
            
                
            const myClipboardEl = document.getElementById('myClipboard')
            const clipboard = new te.Clipboard(myClipboardEl)
            clipboard.dispose()
            
            
        

    Events

    Event type Description
    copy.te.clipboard This event fires immediately after copying text.
    • JavaScript
            
                
            const myClipboardEl = document.getElementById('myClipboard')
            myClipboardEl.addEventListener('copy.te.clipboard', function (e) {
                // do something...
            })
            
            
        
    • Import
    • Usage
    • Options
    • Methods
    • Events
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2023 Copyright: MDBootstrap.com