3 Popular Embeds for Sharing Code on Medium
Writing about code oftentimes requires sharing code snippets.
While we can use the in-built formatting on Medium to format our code snippet as inline code or code blocks, there are times when we’d like to display code with whistles and bells, such as syntax highlighting and the results of running the code.
In such cases, we can make use of Medium’s embeds. There are at least 17 third-party embeds we can use on Medium.
Among these, GitHub Gists, CodePen.io, and JSFiddle are the three popular embeds on Medium.
In this article, I’ll show how these three popular providers are displayed on Medium and talk about the pros and cons of using them from a reader’s perspective (and this is where I put on my reader’s hat).
Lastly, I’ll show how to insert an embed for those who are not familiar with using embeds.
1. GitHub Gists
Share single files, parts of files, and full applications with readers using GitHub Gists.
Sample of an embed in an article
The embed shows the gist with line numbers. Files saved in a single gist will be displayed one after another.
[Embedded content: e13fe89987afeddeb64b4989f9425bab]
Pros
- It has syntax highlighting and shows a simple and clean interface.
- Readers can save the code snippet via forking and cloning.
Cons
- Readers cannot execute the code directly. They have to either download the code and run it on their computer or use a third-party website.
2. CodePen
CodePen is a social development environment that allows us to share the code and the results of running it with readers. It focuses primarily on front-end languages like HTML, CSS, JavaScript, and preprocessing syntaxes.
Sample
The embed shows a placeholder with the button “Run Pen.”
Pros
- It has syntax highlighting.
- Readers can save the code snippet via forking.
- Readers can view the results of the code without leaving the page they are on and they can adjust the size of the resulting frame from x1 to x0.25.
- They can interact with the pen creator through social features like comments and likes on the CodePen website.
Cons
- Readers have to click on “Run Pen” before they see the code of the embedded pen.
- Readers cannot modify the code directly on the page they are on. They have to be directed to CodePen to make any modifications. However, if you have a pro subscription, your embeds are editable (based on what I read as I don’t have a pro subscription).
3. JSFiddle
JSFiddle is a code editor and playground for JavaScript, CSS, HTML, TypeScript, or CoffeeScript.
We can add boilerplates for popular front-end frameworks like React and Vue.js, and show the results of running our code to readers without requiring them to download and run it on their local machine.
Sample
The embed allows readers to view codes in different tabs, e.g., HTML, CSS, JS, and Results. While it doesn’t allow for modification of code within a Medium article, a reader can click on “Edit” in JSFiddle to do so.
Pros
- It has syntax highlighting and shows a simple and clean interface.
- Readers can save the code snippet via forking.
- They can view the code and run it without being directed away from the website that they are on.
- JSFiddle has a collaborative mode for readers who want to work on the code with other people.
Cons
- Readers cannot modify the code directly on the page they are on. They have to be directed to JSFiddle to make any modifications.
- They may find the JSFiddle website interface intimidating:
How to Embed Content in a Draft
For anyone who has not embedded content in an article before, the instructions can be found on the embeds’ websites.
To embed content on Medium in particular, you can follow the steps below:
- Copy the URL from an embed e.g. https://gist.github.com/tiffam/06d34abb08c5bfad84f269b75db38615.
- In your draft, go to a new line and tap on the icon for embed.
- Paste the URL into the Medium editor, and press Enter to convert that link into an embed.
Author’s Note
Among the three popular embeds, I am most impressed by JSFiddle but I prefer to use CodePen and GitHub Gist. The main reasons being that I’m comfortable using them and I like their website interface.
I love how CodePen features picked pens, projects, and collections on their homepage. It can be an eye-opener to view how people create brilliant work using the same tools as you.
I enjoy using GitHub Gist as it’s a really simple and quick way to share code snippets. I love how it ends each frame with ❤️ by GitHub.
While I don’t use JSFiddle in my articles, I wouldn’t rule out using it if I do go into writing articles on Vue and React.
If there are other code sharing embeds that you enjoy using as either a writer or a reader, I would love to hear what they are and why you prefer them.

