Search code examples
htmlpre

How to display preformatted data in headings?


I am new to HTML. I was trying the following code to work but it did not. Can anyone please help me out why <pre> tag is not working inside <h> tags? I also tried to code tag but it din't worked too.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
        <head>
                <title> Checking Different Headings | Isnt it fun?</title>
        </head>
        <body>
                <h1>  This is a title</h1>
                <h2>  What is life? </h2>
                <h3>  Paragraphs are written using <pre> <p></pre>tags </h3>
        </body>
</html>

Solution

  • The pre element is not what you want there.

    If you are trying to show <p>, you should use &lt;p&gt;.

    The HTML angle brackets (less and greater than characters) are encoded, so they are no longer meaningful in HTML tags.

    Otherwise, the HTML parser believes your <p> is a p element.