Indent code on a web page like in a code editor?

Viewed 2067

Is it possible to wrap indented code on a web page the way it's done in a code editor? See the screenshot comparison below to better understand what I mean:

pre-wrap on a web page:

screenshot 1

Wrapping of indented lines in a code editor:

screenshot 2

What I am implying is that the indented lines maintain indentation even after wrapping. This doesn't seem to happen on web pages. Is there a CSS property that does this? (JavaScript would be fine too.)

NOTE: I am not talking about code highlighting here. It's about indentation of wrapped lines.


If this matters — this is how I am showing code blocks on my web pages:

<pre><code>if ( is_page() && $post->post_parent ) {
  return $post->post_parent;

} else {
  return false;
}
</code></pre>

...and the white-space: pre-wrap; style is applied on pre tag.

1 Answers
Related