I am writing one article on Blogger, There I am unable to format code. The code I am writing is looking like simple text. The site name https://www.blogger.com/ I am using <div class="yourClassName"> code here </div> tag to show formatted code, which is giving below output


enter image description here

output: enter image description here

How can I show code in proper way

  • What is the definition of "yourClassName"?
    – S.L. Barth
    Oct 29 '18 at 16:09

In Blogger's Post-editor, make sure that you have selected Show HTML literally under the Options > Compose-mode sidebar:

enter image description here


What Blogger shows is HTML; you can use the <pre> and <code> tags as you would in normal HTML.

It's been a while since I last worked with Blogger, but IIRC it has an editor that lets you use HTML directly. Your <div class="yourClassName"> should work if you put it there, if yourClassName has been defined properly. Which, in the case of computer programming code, usually assumes a monospaced font, among other preferences.

There are a number of resources that can help you format; I found this one that uses only <pre> and <code> to get your code in code formatting.

There is also this old, off-topic question on Stack Overflow that recommends various online resources. Since it's old, you'll have to experiment a little to see what still works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.