HyperText Markup Language/Tag List/code
Use
editWith the code
element you can define, as the name says, code. This could be any code, PHP, C++, HTML anything. Anywhere you have some code in a line of text you should use a code
element to indicate it, e.g.
The html
element must contain exactly one body
element.
Using the element consistently allows you to specify a special layout in CSS for code.
If you are writing an article that uses code you will probably want to use the related elements:
- var
- a variable in computer code;
- kbd
- text the reader should type at the keyboard;
- samp
- sample output from a program or script.
Example
edit<code><?php echo 'Hello World!';?></code>
Multi-line blocks of code should be wrapped in a pre
element to preserve formatting.
<pre>
<code>
// Prints the authors' names as
// surname, forename
for (Iterator i = authorList.iterator(); i.hasNext(); ) {
Person author = (Person)i.next();
System.out.println(author.surname() + ", " + author.forename());
}
</code>
</pre>
Standard attributes
editMore info
editTag phrase elements on W3Schools