Code identifies a short piece of computer code inside normal prose, such as an HTML tag name or file name.
What You Need to Know
The element gives meaning, not necessarily a complete syntax-highlighting system. Put longer code examples inside pre and code together.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Here is a simple example to experiment with. Type it, save the file, and check what the browser displays.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<p>Write <code><h1></code> for a top-level heading.</p>
<p>Use <code>index.html</code> as a common start file.</p>
<p>Inline code stays inside a sentence.</p>
Let’s Understand the Example
- Code identifies a piece of computer code within prose.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
Look for the text “Write” in the page. If the visible result surprises you, inspect the rendered elements to see what the browser actually built.
What Should You See?
The page should include “Write”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Mark two command names inside a paragraph with code.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Using code for a whole multi-line example without preserving its formatting.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- Code identifies a short piece of computer code inside normal prose, such as an HTML tag name or file name.
- Code identifies a piece of computer code within prose.
- The element gives meaning, not necessarily a complete syntax-highlighting system. Put longer code examples inside pre and code together.