Open In App

Which Characters Should Be Escaped Inside A “pre” tag?

The <pre> tag defines pre-formatted text. Everything (generally, text and code snippets) in a <pre> tag element is displayed in a fixed-width font, and preserves both spaces and line breaks in them. In other words, if anyone wants to show their code snippets on a web page, they can simply enclose their code in the tag.

But there are certain things which most of people completely miss. There are some reserved characters in the <pre> tag. Reserved characters are those characters that are meant to serve a specific or reserved purpose. So here is the list of all the reserved character that should also be escaped while writing the code inside it:



As already mentioned there are some reserved characters in <pre> tag. These characters have a specific meaning and if we put these characters inside our <pre> tag, it will treat them as a reserved character, and hence, we need to escape them.

Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>Page Title</title>
</head>
  
<body>
    <center>
        <h2 style="color: green;">GeeksforGeeks</h2>
        <p>A Computer Science Portal for Geeks</p>
        <pre>
    <h2>GeeksforGeeks</h2>
    <p>A Computer Science Portal for Geeks</p>
</pre>
    </center>
</body>
  
</html>

Output:



Some other special symbols which needed to be escaped along with their entity name and entity number are :

Symbols Entity name Entity Number
Non-Breaking Space ( ) &nbsp; &#160;
Registered Trademark (®) &reg; &#174;
Copyright (©) &copy; &#169;
Euro (€) &euro; &#8364;
Pound (£) &pound; &#163;
Cent (¢) &cent; &#162;

Article Tags :