Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > HTML/XHTML

  • Print
  • + Share This
This chapter is from the book

Marking Up Code

If your content contains code samples or file names, the code element is for you (red-a.jpg and red-b.jpg).

red-a.jpg The code element indicates that the text is code or a file name. If your code needs to display < or > signs, use the &lt; and &gt; character entities, respectively (see the last tip). Here, the second instance of code demonstrates this. If you were to use < and >, the browser would treat your code as an HTML element, not as text to display.


Click to view larger image

red-b.jpg The code element’s text even looks like code because of the monospaced default font.

The examples show code used in a sentence. To show a standalone block of code (outside of a sentence), wrap the code element with a pre element to maintain its formatting (see “Using Preformatted Text” for an example).

To mark up code or a file name

  1. Type <code>.
  2. Type the code or file name.
  3. Type </code>.
  • + Share This
  • 🔖 Save To Your Account