-1

I want to show code like "code" in HTML : [note : unlimited code can use]

Example:
‹img src='#' title='demo title'›‹/img›
i used <code> or <pre> but they both did not work

i dont want to used php, jquery or java script code.
Just html codes just like pre or code tags

milo526
  • 5,012
  • 5
  • 41
  • 60
barnameha
  • 371
  • 2
  • 17
  • 1
    possible duplicate of [Display HTML code in HTML](http://stackoverflow.com/questions/2820453/display-html-code-in-html) – Quentin Nov 11 '13 at 10:10

6 Answers6

1

You need to escapse the string:

<code>&lt;img src='#' title='demo title'&gt;&lt;/img&gt;</code>

Escapse HTML Entities: http://www.htmlescape.net/htmlescape_tool.html

Tony Dinh
  • 6,668
  • 5
  • 39
  • 58
  • i want dont use any links for convert because i designed a chat windows , i want user when typed any codes shows results just like codes not executed code – barnameha Nov 11 '13 at 10:11
1

You can use a CDATA section

like this :

<![CDATA[Your <code> here]]>
Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54
  • CDATA sections are only supported in browsers when parsing `application/xhtml+xml` (and other XML) documents. I'm not aware of any browser that supports them in `text/html` documents. – Quentin Nov 11 '13 at 10:09
  • so your answer is not good because i dont want used for application/xhtml+xml format i want used just like html – barnameha Nov 11 '13 at 10:18
0
&lt;img src='#' title='demo title'&gt;&lt;/img&gt;

Easier with PHP: http://php.net/manual/de/function.htmlspecialchars.php

Christine
  • 125
  • 8
0

This already has a bunch of implementations, and it is better not to invent the bicycle, but use on of that: http://www.jquery4u.com/plugins/10-jquery-syntax-highlighters/

0

You can use the tag xmp which is Depreciated one, but still works . https://developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp.

<xmp>‹img src='#' title='demo title'›‹/img›</xmp>

OR

keep your code in a textarea inside a form, like:

   <form>
     <textarea>
       ‹img src='#' title='demo title'›‹/img›
    </textarea>
   </form>

OR (recommended)

you can use pre tag with code tag:

 <pre>
   <code>‹img src='#' title='demo title'›‹/img›</code>
 </pre>
shemy
  • 573
  • 1
  • 5
  • 15
  • i said pre now worked because need escaped charchters ,i dont want use escaped charachters - here http://jsfiddle.net/barnameha/hF985/ how can delete vertical space between two xmp tags?(i used style margins:0px;padding:0px but not worked – barnameha Nov 11 '13 at 10:28
  • pre code with inline code tag not worked u can see (http://jsfiddle.net/barnameha/xdwB5/) – barnameha Nov 11 '13 at 10:33
  • 1
    i edited my jsfiddle and worked i added style http://jsfiddle.net/barnameha/hF985/1/ thanks – barnameha Nov 11 '13 at 10:40
-1
<code>&lsaquo;img src='#' title='demo title'&rsaquo;&lsaquo;/img&rsaquo;<code>

just copy paste the code you will get what you want

O/P:-

<img src='#' title='demo title'></img>
vinay Maneti
  • 1,447
  • 1
  • 23
  • 31