How do I show HTML code on a web page.

Discussion in 'HTML & Website Design' started by CaffinePhil, Mar 18, 2008.

  1. #1
    Hi, I am wanting to show someone a h1 tag like it appears in html

    <h1>heading goes here</h1>

    How do I get aroudn the browser rendering this tag? I have tried the <pre> and <code> tags but they don't seem to work.
     
    CaffinePhil, Mar 18, 2008 IP
  2. matthewbeckman

    matthewbeckman Peon

    Messages:
    140
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use the XMP tag

    <xmp> code here </xmp>
     
    matthewbeckman, Mar 18, 2008 IP
    Halobitt likes this.
  3. ae36

    ae36 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Could also include the content with the HTML number.

    HTML number translation site www.ascii.cl/htmlcodes.htm
     
    ae36, Mar 18, 2008 IP
  4. ifortune

    ifortune Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There are couple of ways...One is to use a textarea tag as the characters within the <textarea> tags does not get parsed.

    <textarea>

    Code You Want Display

    </textarea>


    Another way is to use an html coded Character Set (listed here at the W3C).

    Example:

    To display

    <p><a href="#top"><img src="img/top.gif" border="0" width="33" height="16" alt="go to top" /></a></p>


    you would use

    &lt;p&gt;&lt;a href="#top"&gt;&lt;img src="img/top.gif" border="0" width="33" height="16" alt="go to top" /&gt;&lt;/a&gt;&lt;/p&gt;


    One handy tool for you to convert into html coded Character Set

    http://www.felgall.com/htmlt47.htm
     
    ifortune, Mar 18, 2008 IP
  5. CaffinePhil

    CaffinePhil Banned

    Messages:
    945
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Cheers everyone, will give those a try, Think I like the look of the text box though.
     
    CaffinePhil, Mar 19, 2008 IP
  6. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #6
    <xmp> and textarea are the wrong way to do it. So yeah, don't do them.

    Use the following signs for characters:

    < = &t;
    > = &lt;
    " = &quot;


    BP
     
    blueparukia, Mar 19, 2008 IP
  7. CaffinePhil

    CaffinePhil Banned

    Messages:
    945
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Why are they the wrong ways, will they not validate?
     
    CaffinePhil, Mar 19, 2008 IP
  8. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have no clue what xmp is, but a while a text area will validate, it's not semantically the right way to write a site. Textarea means something and "code showing" isn't it.
    It would be the same as having a <p> styled in CSS to look like a header to use in place of the <h1>. That will validate too, it's just not semantic (removes the meanings of the tags).

    I would recommend the <pre>(preserve) or <code> tags for short bits of code.
     
    Stomme poes, Mar 19, 2008 IP
  9. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #9
    In almost 5 years, this is the first time I've ever heard of an <xmp> element.

    I would use character entities, so would 99% of experienced developers.
    &lt; in place of <
    &gt; in place of >

    Using the character entity of &quot; in place of a quote is a little overboard IMO, but that one's up to you.

    <pre><code>
    &lt;body&gt;
       &lt;div&gt;text&lt;/div&gt;
    &lt;/body&gt;
    </code></pre>
    Code (markup):
    Internet Explorer will act strange in the sense of ignoring newlines with the formatting of a <pre><code> combination sometimes, forcing you to explicitly tell it how to handle it with CSS.
    pre code {
       white-space: pre;
    }
    Code (css):
     
    joebert, Mar 19, 2008 IP
  10. dipal76

    dipal76 Well-Known Member

    Messages:
    3,085
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    138
  11. CaffinePhil

    CaffinePhil Banned

    Messages:
    945
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Again thanks for all the replies, will try to stick with the semantic methods. ;o)
     
    CaffinePhil, Mar 19, 2008 IP
  12. QiSoftware

    QiSoftware Well-Known Member

    Messages:
    805
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    158
    #12
    I always use this method, because it works with all browsers.

    Q...
     
    QiSoftware, Mar 19, 2008 IP
  13. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Marc Fraser, Mar 19, 2008 IP
  14. CaffinePhil

    CaffinePhil Banned

    Messages:
    945
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Thanks Marc, That will save me a load of time ;o)
     
    CaffinePhil, Mar 20, 2008 IP
  15. paul_delaney

    paul_delaney Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Nice job, will use this for future projects!
     
    paul_delaney, Mar 20, 2008 IP
  16. matthewbeckman

    matthewbeckman Peon

    Messages:
    140
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Wow, I have learned a lot from this thread :D I have been designing for years, and I guess I really have never had to embed HTML code on a HTML page. In class we just briefly went over the <xmp> tag. That sounds pretty obsolete now and doesn't seem to be W3 valid. I guess just ignore my post!
     
    matthewbeckman, Mar 24, 2008 IP