If you write about programming, APIs, or data analysis, clear code formatting can make or break your article. Mediumโs editor makes it simple to share code properlyโwithout breaking your flow or your readersโ screens.
What Are Code Blocks on Medium?
Medium offers two main ways to format code: inline code and code blocks.
Inline code is used for short snippets that appear inside a sentence.
For example:print("Hello, world!").
You can apply this format by highlighting text and choosing Inline Code from the text toolbar.Code blocks, on the other hand, are meant for longer, multi-line snippets.
They preserve indentation, spacing, and use a monospace fontโmaking them ideal for tutorials and technical posts.
How to Add Code Blocks
To insert a code block in the Medium editor:
Click the โ+โ icon on a new line.
Select โCode blockโ, or simply type
/codeand press Enter.Paste or type your code into the box.
Medium currently does not support syntax highlighting, so the code appears as plain text. That said, itโs clean, readable, and works well across devices.
When to Use Code Blocks (and When Not To)
Use a code block when:
Youโre showing more than one line of code.
Youโre walking readers through a function, query, or algorithm.
Youโre sharing config or data snippets (e.g., JSON, YAML, SQL).
Use inline code instead when:
Youโre referring to a variable, command, or keyword inside a sentence.
You want to maintain sentence flow, like when you write:
Call thefetch()function before rendering results.
Avoid using code blocks for:
Quoting text or markdown that isnโt actual code.
Extremely long filesโlink to your GitHub repo instead.
Best Practices
Explain before and after each block. Context helps non-developers follow along.
Keep it short and readable. Aim for 10โ20 lines per snippet max.
Check indentation. Medium preserves spaces exactly as pasted.
Skip screenshots. Text-based code is more accessible and SEO-friendly.
Why This Matters
Good formatting shows readers that you respect their time. It turns technical chaos into clarityโand makes your posts feel polished and professional.
You can also share your Medium tutorials beyond the platform. Sites like ManyStories.com help writers reach new readers by linking all their work in one place, whether itโs hosted on Medium, WordPress, or GitHub Pages. Add your story today at ManyStories.com.