3

I'm asking on how could we show html code on a tutorial html website, for example to show to user how to make a link?

<a href="#">text</a>
3

5 Answers 5

4

With CDATASection. The CDATASection object represents a CDATA section in a document.

A CDATA section contains text that will NOT be parsed by a parser. Tags inside a CDATA section will NOT be treated as markup and entities will not be expanded.

You can use it in XML for sample :

<![CDATA[<tag>Some text</tag>]]>

It Will interpreted such as :

&lt;tag&gt;some text&lt;/tag&gt;

Or in program Output. Sample with CSS :

<style type="text/css">
/*<![CDATA[*/
body { background:black;  }     
/*]]>*/
</style>

Hope this help you.

Sign up to request clarification or add additional context in comments.

Comments

4

Use HTML entities for it.

E.g.:

  • &lt; for <
  • &gt; for >

<pre>, <code> or <xmp> can be used but have compatibility issue.

Example:

  1. &lt;a href="#"&gt;text&lt;/a&gt;

  2. <span class="code"><span class="lt">&lt;</span>a href="#"<span class="gt">&gt;</span>text<span class="lt">&lt;</span><span class="fs">/</span>a<span class="gt">&gt;</span></span>

CSS for Example 2:

.code {
    font-family:Courier;
    color:#DF42AA;
}
.lt, .gt, .fs{
    font-family:Courier;
    color:#032F82;
}

Comments

3

replace < by &lt; and > by &gt;

Comments

2

An other way with CSS :

code::before { content:'<'; }
code::after { content:'>'; }

And then, your HTML code will be :

<code>a href="#"</code>text<code>/a</code>

From this website about CSS (but in french).

Comments

0

use

&lt; for < and &gt; for >

A shortcut is "if you use &lt; for <,and don't use &gt; for >, then your output will be same as using both &lt; and &gt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.