HyperText Markup Language/Tag List/code

From Wikibooks, open books for an open world
Jump to navigation Jump to search


With 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:

a variable in computer code;
text the reader should type at the keyboard;
sample output from a program or script.


<code><?php echo 'Hello World!';?></code>

Multi-line blocks of code should be wrapped in a pre element to preserve formatting.

  // 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());

Standard attributes[edit]

More info[edit]

Tag phrase elements on W3Schools