+ 3

How can I write a block of code that would be displayed on the output?

I want to display a piece of code in the output. But when I try to put the piece of code in <code>..... </code> tag, it is displaying the code after executing it. I want to do it just like comments, the code should not be executed but it should be displayed in the output. How can I do so?

26th Apr 2018, 11:37 PM
Keshav Kishor Ram
6 ответов
+ 3
Can you post your code here?
27th Apr 2018, 12:16 AM
Mickel
Mickel - avatar
+ 3
I'm not using PHP. Only HTML & CSS
27th Apr 2018, 4:17 AM
Keshav Kishor Ram
+ 2
Use this tool to build an escaped version of your code https://www.freeformatter.com/html-escape.html Then drop it in between the <code> tags. You can style it like this to give it a nice Box around the code .codebox { /* Below are styles for the codebox (not the code itself) */ border: 1px solid black; background-color: #f0f0f5; width: 100%; overflow: auto; padding: 10px; } example <div class="codebox"> <code>&lt;article class=&quot;panel&quot; id=&quot;page2&quot;&gt;</code> </div>
27th Apr 2018, 11:03 AM
Mike Choy
Mike Choy - avatar
+ 1
Try using <pre></pre> tags. I’ve never tried, but it may work
26th Apr 2018, 11:56 PM
Ariela
Ariela - avatar
+ 1
The <code> just styles what is inside it. Meaning it will still render any HTML inside. Read this: https://stackoverflow.com/questions/18131084/html-code-tags-no-execute?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa If you're using PHP convert code using htmlspecialchars(). See my example here: https://code.sololearn.com/WeiSobPicPCe/?ref=app PHP example of <code> tags here: https://code.sololearn.com/wEXoh23I2Lvk/?ref=app
27th Apr 2018, 1:16 AM
Emma
+ 1
Abhishek Ram Well then use &lt;b&gt; method for escaping your HTML. &lt;b&gt; is what <b> looks like escaped. Use this website to escape the HTML for you, then put the result I'm between the <code> tags.
27th Apr 2018, 4:20 AM
Emma