Back to knowledge base Updated August 31, 2025

How do I create a code block in Notion?

Creating code blocks in Notion requires just three simple methods, each designed to fit different workflows and preferences. Whether you're documenting API endpoints, sharing snippets with your team, or organizing technical notes, Notion offers flexible approaches that make code formatting both intuitive and powerful. The most popular method involves using the slash command "/code" followed by Enter, which instantly generates a formatted code block ready for your input. Understanding these creation methods—along with their formatting capabilities—transforms how you organize and present technical content within your workspace.

The fastest way to add a code block is typing "/code" on any new line and pressing Enter. This slash command approach feels natural and keeps your hands on the keyboard, maintaining your coding flow. Alternatively, you can hover to the left of any line until the "+" icon appears, click it, and select "Code" from the block menu. For shorter code snippets within paragraphs, wrap text in single backticks (`) to create inline code formatting instead of full blocks.

Once you've created your code block, click inside it to start typing or paste your code directly. Notion automatically preserves whitespace and indentation, which proves crucial for languages like Python where spacing affects functionality. The real power emerges when you select a programming language from the dropdown at the top-left of the block. Notion supports dozens of languages including JavaScript, Python, Java, HTML, CSS, and SQL, applying syntax highlighting that makes your code more readable and professional.

Advanced formatting options enhance your code blocks further. Right-clicking the block or using the menu icon reveals options like "Wrap code," which prevents horizontal scrolling by allowing long lines to break naturally. You can also add captions below blocks for context and use the copy icon to quickly transfer code to your clipboard. For lengthy snippets, consider placing code blocks inside toggle blocks (created with "/toggle") to keep pages organized and scannable.

While these features work seamlessly across desktop and web versions, mobile users may find some advanced options less accessible. Additionally, Notion defaults new code blocks to "Plain Text," so you'll need to manually select your programming language each time for proper syntax highlighting. Despite these minor limitations, code blocks in Notion provide a robust foundation for technical documentation, making complex information more accessible and your workspace more organized.

Give Notion Personal Finance Superpowers

Still manually tracking your spending in Notion? Use Latwy to connect your accounts and automatically sync your transactions each day. Learn more about Latwy, then start a free 30-day free trial.

Copyright © 2025 Amalgamated Hams LLC. All rights reserved.