Page 118 - HTML5
P. 118

Chapter 26: Marking up computer code




        Syntax



            •  <pre>Formatted text</pre>
            •  <code>Inline Code</code>


        Remarks



        The code element should be used for any kind of "string that a computer would recognize" (HTML5
        ), for example:


            •  source code
            •  terms from markup/programming languages (element names, function names, etc.)
            •  file names

        Related elements


        For variables, the var element can be used.


        For computer output, the samp element can be used.

        For user input, the kbd element can be used.


        Examples



        Inline with


        If a sentence contains computer code (for example, the name of an HTML element), use the code
        element to mark it up:


         <p>The <code>a</code> element creates a hyperlink.</p>


        Block with


          and

        If the formatting (white space, new lines, indentation) of the code matters, use the pre element
        in combination with the code element:

         <pre>
             <code>
             x = 42
             if x == 42:
                 print "x is …          … 42"
             </code>
         </pre>




        https://riptutorial.com/                                                                             102
   113   114   115   116   117   118   119   120   121   122   123