How to auto-select HTML macro contents in Confluence cloud

This article explains how a user can copy the contents from the HTML macro in a confluence page with an option/button with an HTML script.


  • Create a confluence page in the cloud environment & add an HTML macro.

  • Add the below code to your HTML content:
    The content can be modified as per your requirement. Here in the snippet, replace the value parameter with the one you want to show to the user under the “Add the content you want to see“ section.

    <!-- HTML code to copy into clipboard --> <!-- Include libraries --> <!-- a. Include font-awesome for the copy icon --> <head> <link rel="stylesheet" href=""> <!-- b. Include the copy library <script src="" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> --> <script src=""></script> <!-- Instantiate clipboard by passing a string selector --> </head> <body> <!-- test --> <input id="foo" value="bam -i |grep byn > /tmp/mpplist_alive || grep byn /etc/opt/teradata/tdconfig/mpplist|awk '{print $1}' > /tmp/mpplist_all"> <!-- Trigger --> <button class="btn" data-clipboard-target="#foo"> <img src="assets/clippy.svg" alt="Copy to clipboard"> </button> <script>// Select elements const target = document.getElementById('foo'); const button = target.nextElementSibling; // Init clipboard -- for more info, please read the offical documentation: var clipboard = new ClipboardJS(button, { target: target, text: function() { return target.innerText; } }); // Success action handler clipboard.on('success', function(e) { const currentLabel = button.innerHTML; // Exit label update when already in progress if(button.innerHTML === 'Copied!'){ return; } // Update button label button.innerHTML = 'Copied!'; // Revert button label after 3 seconds setTimeout(function(){ button.innerHTML = currentLabel; }, 3000) }); </script> </body>
  • Publish the page to see the result.

  • Please ensure, the HTML for confluence app is installed in your environment.

  • Ensure to have proper permission to perform/apply changes.