I recently started to learn HTML and CSS.
When I use <code></code>
, it just shows up as plain, black and white text, although I would like it to automatically highlight the syntax appropriately.
It currently looks like this:
text = "Hello World!"
print(text)
I would like it to look like this:
text = "Hello World!"
print(text)
Is it possible to do that with just HTML and CSS?
2
Answers
No.
It requires more detailed markup and CSS.
e.g.
To do it automatically you need to involve a programming language. You could use it to preprocess your code before it is delivered to the browser, or use client-side JavaScript to do it after the page has loaded.
There are various libraries available to to this.
For syntax highlighting, you typically need to use additional tools or libraries. One common approach is to use JavaScript-based syntax highlighting libraries like "highlight.js" or "Prism.js." These libraries can dynamically apply appropriate styles to different parts of the code to make it visually appealing and easy to read.