Harry
Harry

Reputation: 13329

Show and style HTML source code in HTML page

I would like to display HTML source code in an HTML page. So I want it to look like it looks in your text editor. The source will be the complete source code, from the <html> tag to the end. So it needs to include the <head> and <body> with all styles in the <head>.

How would I do this?

Upvotes: 1

Views: 3071

Answers (1)

Tom Dezentje
Tom Dezentje

Reputation: 631

<textarea name="Source Code"></textarea>

then set the value of that text area to

document.getElementsByTagName('html')[0].innerHTML

You might need to add the html tags again. But that should be no problem

Edit 2018

Someone upvoted this. I would highly recommend you take a look at https://highlightjs.org/. Its a very good solution for the stated problem.

Upvotes: 2

Related Questions