Inline Code
Inline code is a simple way to highlight a word or phrase as code. To format text as inline code, wrap the word or phrase in back ticks (`).
You can write inline code like this: word
or phrase
.
Markdown code
`word` or `phrase`
Inline code is great for small snippets, filenames, commands, or code elements that are part of a larger sentence.
Code blocks
For larger chunks of code, markdown provides fenced code blocks. These blocks allow you to include multi-line code snippets, optionally with syntax highlighting for various programming languages.
To create a code block, enclose the code in three back ticks (```
). Here's an example:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```java
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
You can add an optional title or description after the language name to provide context about the code snippet.
Tips for using Code blocks
- Always specify the language for better readability with syntax highlighting.
- Use inline code for short snippets and fenced blocks for larger code.
- When including sensitive information (e.g., API keys), avoid publishing code blocks with actual data.