Skip to content
Related Articles

Related Articles

Improve Article

How to display HTML tags as plain text in HTML ?

  • Last Updated : 20 Sep, 2021
Geek Week

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

1. Using <plaintext> element: 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.

2. HTML entities: The second and only option available is using html entities. < ,> are reserved characters in HTML, In order to display this 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 below table for required html entities:

Sign

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

Example 1: In the first example, we are using html entity names to display body element and paragraph element on 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 above code, “<” and “>” is simply replaced by their respective html entities.<pre></pre> is html element which defines preformatted text.

Example 2: In below example, we are trying to display html entity name for “<” using 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;”

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :