How to add plain text code in a webpage?

Look at how this website itself achieves this:

<p>For example, if I have <code>&lt;p&gt;&lt;div&gt;&lt;/div&gt;&lt;/p&gt;</code>, I want the div to display in the browser as text not have the browser interpret it as html. Is this complicated to do?</p>

You need to replace the < and > with their HTML character entities.


There are many ways to use:

  1. Replace < with &lt;

    `&lt;h1>This is heading &lt;/small>&lt;/h1>`
    
  2. Place the code inside </xmp><xmp> tags

    <xmp>
        <ul>
            <li>Coffee</li>
            <li>Tea</li>
        </ul>
    </xmp>
    

I do not recommend other ways because they do not work on all browsers like <plaintext> or <listing>.

Tags:

Html