Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to display HTML tags as plain text in HTML ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will learn how to display HTML tags as plain text in HTML. We can replace the plain text by using < with   &lt; or &60; and >   with  &gt; or &62; on each HTML tag.

Basically, there are two methods for displaying HTML tags as plain text.

  • Using <plaintext> element: The plaintext element is deprecated which means this feature is no longer supported. Though some browsers might still support it, it is not recommended to use.
  •  HTML entities: The second and only option available is using HTML entities. <,> are reserved characters in HTML, In order to display these reserved characters you have to replace them with HTML entities. You can learn more about entities here. You can either use entity name or entity number initializing them with  & and ending them with ;

Refer to the below table for the required HTML entities:

Sign

DescriptionEntity nameEntity number
<Less than(start of html element)&lt;<
>Greater than(end of html element)&gt;>
Double quotation&quot;"
&Ampersand ( beginning of html entity)&amp;&

Example 1: In the first example, we are using html entity names to display the body elements and paragraph elements on the web page.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Plain text </title>
</head>
<body>
    <pre>
        Paragraph element: <p> </p>
        Body element : < body > < /body >
    </pre>
</body>
</html>

Output:

Output

Explanation: In the above code, “<” and “>” is simply replaced by their respective html entities.<pre></pre> is html element that defines preformatted text.

Example 2: In the below example, we are trying to display html entity name for “<” using the entity name for “&” sign.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Plain text demo</title>
</head>
<body>
    <pre>
        < is entity name for <
    </pre>
</body>
</html>

Output:

Output

Explanation: In above example, “&” is replaced with “&amp;” and “<“ is replaced with “&lt;”


My Personal Notes arrow_drop_up
Last Updated : 05 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials