Possible Duplicate:
How do I format my code blocks?
When I put HTML into the form field for Stack Overflow questions, it doesn't show up. Why is this, and is there a way to get HTML markup to show up?
-
Maybe you should read the bar at the right of the textarea where you write your question, or better yet.kuroir– kuroir10/24/2011 04:47:46Commented Oct 24, 2011 at 4:47
-
See this as well: stackoverflow.com/editing-helpuser152859– user15285910/24/2011 07:59:06Commented Oct 24, 2011 at 7:59
4 Answers 4
Paste your code in the text area; select your HTML code, and click on the "{}" icon above. The code will get indented, and it will show the code in your question.
-
3This is failing when you want to place the code sample after bullet pointsMick– Mick03/01/2017 01:46:56Commented Mar 1, 2017 at 1:46
-
It works but when I do that my multiline html code is on the same line and I don't get the color coding. How can I get multiline colored html code to show up?Sulli– Sulli06/01/2018 13:46:04Commented Jun 1, 2018 at 13:46
It doesn't show up because it gets parsed as (invalid) HTML. You can use HTML to format your post, and it doesn't get shown if it's used for formatting. Here's the list of valid HTML tags. As that page says,
HTML tags not on this list are stripped from the output.
Notice that, for example, <html>
is not on that list. If you have a pair of <html>
tags at the start and end of your sample, they will be stripped, and your sample will display nothing at all.
You need to tell the parser not to render the sample, and instead to display it. You can do that in one of three ways:
For short, inline samples like my use of
<html>
above, use backticks (next to the 1 on your keyboard). The above line looks like:my use of `<html>` above
For longer samples, use block code formatting. To do this, indent every line of the block by 4 spaces. You can do this manually, in a text editor, or by selecting the text and hitting the
{}
button in the toolbar:enter image description here
Remember that you can use HTML to format your post. Enclose your code in
<pre><code>
to invoke the syntax highlighter and format your text as code.
And this question basically proofs this article:
http://www.codinghorror.com/blog/2009/10/treating-user-myopia.html
You indent the code 4 lines and that should work.
-
Yep, I kept clicking and clicking {} around my code - but only trying once the 4x indent as suggested, it worked right away. Thanks!gnB– gnB07/23/2014 18:27:18Commented Jul 23, 2014 at 18:27
-
That must be a blog about how disappointing it is that you have to put HTML in a code block.Jonathan Mee– Jonathan Mee01/14/2016 12:54:59Commented Jan 14, 2016 at 12:54
Write your HTML code, select it, and click the "{}" icon on the top of that textarea.
<html><head></head><body>html code</body></html>