How and When to Use Code Blocks in the Medium Editor

How and When to Use Code Blocks in the Medium Editor

A simple guide to using inline and block code formatting on Medium for developers and technical writers.

MediumCode BlocksCodingTechnical Writing

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:

  1. Click the “+” icon on a new line.

  2. Select “Code block”, or simply type /code and press Enter.

  3. 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 the fetch() 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.