code must be within pre (inline elements can't contain block-level elements) : code « Tags « HTML / CSS






code must be within pre (inline elements can't contain block-level elements)

    

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Listing 4-18. Code</title>
</head>

<body>

  <pre><code>
  function helloWorld() { 
    var button = document.getElementById("button"); 
    if (button) { 
      button.onclick = function(){ 
        alert("Hello world!"); 
      } 
    } 
  }
  </code></pre>

</body>
</html>

   
    
    
  








Related examples in the same category

1.code Element For Adding Code to Your Web Pages
2.Displaying blocks of code online
3.Blocked and preserved Code
4.Formula input
5.code margin: 5px 0;
6.code padding: 10px;
7.code text-align: left;
8.code display: block;
9.code overflow: auto;
10.code font: 500 1em/1.5em 'Lucida Console', 'courier new', monospace ;
11.code background: #F5F5F5;
12.code border-left: 3px solid #D4D4D4;
13.code font-family:courier, monospace;
14.code font-size:12px;
15.code font-weight:bold;
16.code border:1px solid #000000;
17.code {display:block;}
18.code font-family: courier;
19.code color: #000000;
20.code font-size: smaller;
21.code background-color: #d6d6d6;
22.code padding: 2px;
23.code margin: 5px;
24.code padding: 3px;
25.code background-color: black;
26.code color: #FFFFFF;
27.Code style
28.'code' Example