Using PRE Element to Display Code Text – HTML5

Marking Up Source Code the Right Way

The pre element should be used for text that has typographic formatting that affects the meaning of the content, such as in poems, ASCII art, transcripts, and, of course, computer code.

If you want to represent a block of source code in your HTML document, you should use a code element nested inside a pre element. This is semantic, and functionally, it gives you the opportunity to tell search engine crawlers, social media apps, RSS readers, and other interoperating web services that the content is computer code.

Free tool to format/escape code for display:
http://www.freeformatter.com/html-escape.html

Read the rest at:
https://www.sitepoint.com/everything-need-know-html-pre-element/

Advertisements