How to Embed Code in Medium

Two easy methods for embedding code in your Medium article.

Abhijith Chandradas
Feb 5 · 3 min read

When writing an article about coding, writers often find it difficult to add code to the article. Code in normal text ruins the formatting and does not differentiate the text from the code. Some writers overcome this problem by uploading the screenshot of the code.

In this article I will explain two easy methods to embed code into your Medium article.

Method 1: Embed directly in medium

To embed code directly in medium, use the following shortcut key:

  • Mac : Command+ Option+6
  • Windows: Control + Alt + 6
  • Linux: Control + Alt + 6

When you press these keys, a grey box as below will appear, inside which you can write your code.

Check how the code formatting is retained . The code stands out with the help of typewriter font and highlighting.

Method 2: Embed using Github Gist

Github Gist is a much more appealing and readable option compared to directly embedding using Medium.

First, you have to sign up to Github gist and login to your account.

On the top left of Github gist page, you can find a ‘+’ sign, you can press on it to create a new gist.

You’ll be taken to the next page where you have to enter the following details:
i. gist description
ii. your code snippet’s title or filename
iii. your code snippet to be shared

You can save it as a public or secret gist.
If you want to publish it on medium, then you should save your gist as public.

Copy the link to your gist (url) or get the sharable link.
It can be embedded into Medium article by simply pasting it in a new line or using embed link option.

This is how your gist will then look on medium.

This code is written for an article on quadrant analysis.

The advantage of using Git Gist is that when the code is edited in Gist, the changes will be reflected in the Medium article and wherever the code is shared.

Video Format

If you prefer the video format of content, you can check out the following YouTube Video.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Abhijith Chandradas

Written by

Data Analyst | Hacker | Financial Analyst | Freelancer | IIM MBA | Opensource | Democratize Knowledge | https://www.youtube.com/channel/UCLpBd4gzfIBXm2BPpdHOWdQ

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.