Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub


npm version

Add copy button to your prismjs’ code blocks.


How to make it work


How to install

npm install --save gatsby-transformer-remark gatsby-remark-prismjs gatsby-remark-prismjs-copy-button

How to use

  1. Add it to gatsby-config.js:

    NOTE: You MUST add gatsby-remark-prismjs-copy-button before gatsby-remark-prismjs, as gatsby-remark-prismjs will transform Code MarkdownASTs to HTML. So gatsby-remark-prismjs-copy-button will unable to find the Code MarkdownASTs to add copy button.

    module.exports = {
      plugins: [
          resolve: `gatsby-transformer-remark`,
          options: {
            plugins: [
  2. In your template.js.

    export const query = graphql`
      query ($slug: String!) {
        markdownRemark(fields: { slug: { eq: $slug } }) {
    export default function Template({ data }) {
      return (
        <div dangerouslySetInnerHTML={{ __html: data.markdownRemark.html }} />
  3. Overwrite the style of the copy button.

    You can overwrite the style of the copy button by adding the following class to your own style.css.

    .gatsby-remark-prismjs-copy-button-container {
      left: 0;
      padding-right: 8px;

How to contribute

If you have unanswered questions, would like help with enhancing or debugging the plugin, it is nice to include instructions for people who want to contribute to your plugin.


This project is licensed under the terms of the MIT license.

© 2023 Gatsby, Inc.