Search code examples
htmlpre

How to share Html tags


I want to share some piece of html code using <pre> and <code> tag. But problem is when I share this code it has converted into html files.

example i want to share this code

   

     <!DOCTYPE html>
    <html>
    <title>HTML Tutorial</title>
    <body>
    
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    
    </body>
    </html>

but when I share this it has converted into a html. how can share as a code so that viewer can view the html tags and code.


Solution

  • You need to encode special characters. You can use online tools to encode characters. Here is the encoded version of your desired snippet:

    &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;title&gt;HTML Tutorial&lt;/title&gt; &lt;body&gt; &lt;h1&gt;This is a heading&lt;/h1&gt; &lt;p&gt;This is a paragraph.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt;
    

    This online tool was used: https://www.web2generators.com/html-based-tools/online-html-entities-encoder-and-decoder