Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add plain text code in a webpage? [duplicate]

Tags:

html

I know it is possible because this website does it, but I tried researching how and just got a bunch of junk, so how do I add tags to a website paragraph without the browser interpreting it as code.

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

I have been writing tutorials for school, and it would be much easier if I could add the code directly to the webpage in text form instead of images, so students can copy and paste it.

like image 656
Tom Nolan Avatar asked Feb 18 '13 03:02

Tom Nolan


People also ask

How do I copy plain text from a website?

Simply browse to a website and select a desired text, then right-click and select - Copy as plain text - from the context-menu. The selected text will be copied to the clipboard without any formatting.

How do you insert plain text in HTML?

The HTML <plaintext> tag is used to render all text in the document exactly as it was typed in, including all tags and even the document tags. This tag ignores all formatting for the rest of the document, displaying all text exactly as is. It cannot be stopped, it cannot be turned off.

How do you clone a website source code?

Cloning a complex website To copy the HTML, select an element and click “Inspect” to open the DevTools. Next, click “Sources” at the top. You'll see the HTML appear on this tab, and you can select it, copy it, and then paste it into a text editor.


3 Answers

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.

like image 146
Matt Healy Avatar answered Oct 28 '22 06:10

Matt Healy


Use the tag <PRE> before a block of reformatted text and </PRE> after. The text between these tags is rendered as monospaced characters with line breaks and spaces at the same points as in the original file. This may be helpful for rendering poetry without adding a lot of HTML code. Try this:

Mary had a little lamb. 
    Its fleece was white as snow.
And everywhere that Mary went
    the lamb was sure to go.
like image 35
Ralph Nelson Avatar answered Oct 28 '22 05:10

Ralph Nelson


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>.

like image 37
Majali Avatar answered Oct 28 '22 06:10

Majali