Solution 1 :

I just discovered, which supports over 189 languages and 91 styles, and way easier to use. There is a code sample below:

  <link rel="stylesheet"
  <script src=""></script>
  <pre><code class="python">def fib(n):
  a, b = 0, 1
    while a < n:
      print(a, end=' ')
      a, b = b, a+b

Origina Post:

Try More info click here and here from Stack Overflow

Or like @EternalHour said, you can use <pre>Your code here</pre> <code>Your code here</code>

Solution 2 :

you can use pygments for styling python codes in your html pages.

Problem :

What are the options to display python code in HTML pages?

I do not want to execute python code in the page, but only produce HTML/CSS pages displaying nicely formatted (with e.g., syntax highlighting) python code snippets as done, for instance, by stackoverflow.

Basically I would like a tool that takes a python file as input and generate an HTML/CSS code.


Comment posted by EternalHour

You can use either

Comment posted by John Montgomery

For syntax highlighting, what you’re looking for is called a code prettifier. There’s a lot of options for that available online, look into it and see if one fits your needs (Stack Overflow doesn’t allow recommendation questions unfortunately).

Comment posted by qouify

@EternalHour : thanks for your answer. I did not know of theses tags

Comment posted by qouify

@john-montgomery : thank you. I did not know it was called like that (code prettifier). I have found a couple of tools that seem nice.


Leave a Reply

Your email address will not be published. Required fields are marked *