How To Properly Format Code In OneNote
Microsoft OneNote is useful for storing programming notes, scripts, commands, configuration files, and code snippets in one place. However, simply pasting code into a OneNote page can make it difficult to read. Indentation may become confusing, long lines can be hard to follow, and code can look almost identical to normal notes.
In OneNote, you can make code much easier to read by using monospaced fonts, proper indentation, highlighting, spacing, and formatting techniques.
OneNote does not provide a full-featured code editor like Visual Studio Code, but you can still create clean and organized code sections for reference, documentation, tutorials, and troubleshooting notes.
In this guide, you will learn how to properly format code in OneNote step by step.
How to Properly Format Code in OneNote?

To properly format code in OneNote, paste the code into a separate text container, select it, and apply a monospaced font such as Consolas or Courier New. Preserve the original indentation, add spacing between code sections, and use bold text, highlighting, or a shaded area to distinguish code from normal notes. For longer snippets, place the code in its own section and add a short explanation above or below it. This makes commands, scripts, and programming examples easier to read and copy.
OneNote does not have a dedicated code-block feature comparable to some modern note-taking applications.
Therefore, the best approach is to combine OneNote’s existing formatting tools to create a clear and consistent code area.
Let’s learn in detail!
Step 1: Create a Separate Area for Your Code
Start by opening OneNote and navigating to the notebook and page where you want to store the code.
Instead of mixing the code directly into a paragraph of ordinary notes, create a separate text container for it. A text container is the area where OneNote allows you to type or paste text on a page.
Click on an empty area of the page and create a new text container. You can then paste or type your code inside it.
Keeping code in a separate area is especially useful when your page contains explanations, instructions, screenshots, and commands. It immediately separates the programming content from the surrounding information.
For example, if you are writing notes about a Python script, you could first write an explanation such as “The following Python code displays a message:” and then place the actual Python code underneath it.
This simple organization makes your OneNote pages much easier to scan later.
Step 2: Paste the Code Without Changing Its Structure
Copy your code from your programming editor, website, or other source and paste it into the OneNote text container.
When possible, use plain text when pasting code. This helps prevent unwanted formatting from the original application from being carried into OneNote.
The most important thing to check after pasting is indentation.
Programming languages such as Python rely heavily on indentation, while indentation is also important for making languages such as JavaScript, C++, Java, and HTML easier to understand.
For example, this Python code should remain properly aligned:
if temperature > 30:
print(“It is hot”)
else:
print(“It is comfortable”)
Do not manually remove spaces simply because they appear unnecessary. Those spaces may be essential to the code or may make its structure easier to understand.
After pasting, compare the OneNote version with the original code to make sure the indentation and line breaks have been preserved.
Step 3: Change the Code to a Monospaced Font
One of the easiest ways to make code look more professional in OneNote is to use a monospaced font.
A monospaced font gives every character the same amount of horizontal space. This is particularly useful for programming because characters line up more predictably.
Select the code you pasted into OneNote. Then open the font options on the OneNote ribbon and choose a monospaced font.
Consolas is a good choice if it is available on your computer. Courier New is another commonly available option.
After changing the font, you should notice that the code looks more like programming text and less like ordinary paragraph content.
You can also increase the font size slightly if the code is difficult to read. For example, if your normal notes use 11-point text, you might use 11 or 12 points for code.
The goal is not to make the code unusually large. Instead, choose a size that remains comfortable to read while keeping the page compact.
Step 4: Preserve Line Breaks and Indentation
Code should generally have one logical instruction or statement per line. Avoid turning a long code block into one large paragraph.
If you notice that several lines have been combined after pasting, undo the action and try pasting the code again as plain text.
Pay particular attention to spaces, tabs, braces, brackets, and quotation marks.
For example, JavaScript code is easier to understand when its structure is preserved:
function greet(name) {
if (name) {
console.log(“Hello ” + name);
}
}
The indentation makes it immediately clear which statements belong inside the function and the conditional statement.
When documenting code in OneNote, readability is just as important as preserving the actual characters. A well-spaced code block is much easier to review when you return to your notes weeks or months later.
Step 5: Use Bold Formatting for Important Code Elements
You can use bold formatting sparingly to draw attention to important commands, filenames, variables, or sections surrounding the code.
However, avoid making the entire code block bold. Too much bold formatting can make programming text harder to read.
For example, if you are documenting a Windows command, you might introduce it with a sentence such as Run the following command in Command Prompt: and then place the command underneath.
This creates a visual distinction between your explanation and the command itself.
For longer programming notes, you can also use bold headings such as Variables, Function, Output, or Important Command around different sections.
Step 6: Use Text Highlighting to Make Code Stand Out
OneNote’s text highlighting feature can help separate code from ordinary notes.
Select the code or a particularly important command and apply a subtle highlight using the formatting controls.
This technique works particularly well for short commands. For example, if you are documenting a troubleshooting procedure, you can place the command in its own line and highlight it so you can quickly identify it later.
For large code blocks, however, highlighting every line may make the page visually overwhelming. In those situations, use highlighting only for important commands or individual pieces of code.
The goal is to create a visual distinction without making the page difficult to read.
Step 7: Add an Explanation Above or Below the Code
Proper code formatting is not only about appearance. Good documentation should also explain what the code does.
Before a code block, add a short explanation describing its purpose.
For example, you could write:
This PowerShell command displays the current Windows version:
Then place the command below it.
After the code, you can explain what the important parts mean. This is particularly helpful if you are creating personal technical notes or tutorials.
Separating explanation, code, and result makes your OneNote page easier to understand when you revisit it later.
Step 8: Add the Programming Language Name
If your OneNote notebook contains code from several programming languages, identify the language before each code block.
For example, write Python Code, JavaScript Code, PowerShell Command, HTML Code, or SQL Query as a heading above the relevant section.
This is especially useful when you have multiple snippets on the same page.
You can also include information such as the purpose of the script, the application where it should be executed, or the expected result.
This turns OneNote from a simple place to paste code into a useful code reference notebook.
Step 9: Use a Consistent Formatting Style
Once you find a formatting style that works for you, use it consistently throughout your OneNote notebook.
For example, you might use Consolas 11-point font for all code, bold headings for programming languages, and highlighted text for commands that need to be copied.
Consistency makes large notebooks much easier to navigate.
You could also create a dedicated section called Code Snippets and organize pages according to programming language or purpose. For example, separate pages could contain Windows Commands, PowerShell, Python, JavaScript, and SQL snippets.
This organization becomes particularly valuable when your collection of code grows over time.
Step 10: Test the Code Before Saving It as a Reference
Finally, do not assume that code is correct simply because it looks properly formatted in OneNote.
If the code is intended to be executed, test it in the appropriate programming environment first. Then paste the verified version into OneNote.
You can add a short note explaining what the code does and whether it requires any special permissions, software, or configuration.
For example, a PowerShell command might require Administrator privileges, while a Python script might require a particular Python version or library.
Adding these details can save you time when you return to the code later.
FAQs
Can OneNote create a dedicated code block?
OneNote does not provide the same dedicated code-block feature found in many programming editors and specialized Markdown applications. However, you can create a similar appearance by using a monospaced font, separate text containers, indentation, spacing, and highlighting.
Which font is best for code in OneNote?
Consolas is a good choice for code because it is a monospaced font designed for programming and technical text. Courier New is another option if Consolas is unavailable.
Can I add syntax highlighting to code in OneNote?
OneNote does not provide the same automatic syntax highlighting available in dedicated code editors. You can manually use bold formatting and text highlighting to emphasize important parts, but this will not automatically identify keywords, functions, strings, or comments.
Why does my code look different after pasting it into OneNote?
The appearance can change because OneNote may inherit formatting from the application or website where the code was copied. Using plain-text pasting can help avoid unwanted fonts, colors, and other formatting.
Can I store programming scripts in OneNote?
Yes. OneNote can be useful for storing code snippets, commands, scripts, configuration examples, and programming notes. For large projects, however, it is better to keep the actual source files in a dedicated code editor, source-control system, or appropriate file storage location and use OneNote for documentation and reference material.
How do I make long code easier to read in OneNote?
Use a monospaced font, preserve indentation, separate different sections with headings, and avoid placing large amounts of code inside ordinary paragraphs. You can also split lengthy scripts into logical sections and explain each section separately.
