Open In App

How to display HTML tags as plain text in HTML ?

Improve
Improve
Like Article
Like
Save
Share
Report

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.

HTML Entities:

Sign

Description Entity name Entity number
< Less than(start of HTML element) &lt; <
> Greater than(end of HTML element) &gt; >
Double quotation &quot;
& Ampersand ( beginning of HTML entity) &amp; &

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.

Example 1: 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

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 either use entity name or entity number initializing them with  & and ending them with ;

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>
        &lt is entity name for <
    </pre>
</body>
</html>


Output:

Output



Last Updated : 12 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads