Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quote in HTML (not blockquote)?

Tags:

html

quotes

I want to some sample code in a html page. How do I do it, for example I want to show a tag and image tag, in stackoverflow I use 4 spaces:

A Tag example:
<a href="your_url"></a>

Image Tag example:
<img...>
like image 379
mysqllearner Avatar asked Feb 11 '10 15:02

mysqllearner


People also ask

How do you quote something in HTML?

The <q> HTML element indicates that the enclosed text is a short inline quotation. Most modern browsers implement this by surrounding the text in quotation marks. This element is intended for short quotations that don't require paragraph breaks; for long quotations use the <blockquote> element.

What is the difference between quote and blockquote in HTML?

q can only contain phrasing content (and it can only be used where such phrasing content is expected). blockquote can only contain flow content (and it can only be used where such flow content is expected).

How do you do a block quote in HTML?

HTML <blockquote> tag is used to define a block of text which is quoted from another source. The Browser usually displays the content within <blockquote> tag as indented text. If you want to insert a long quote then use <blockquote> and for short or inline quote use <q> tag.

How do I use single quotes in HTML?

Can I use single quotes in HTML? Yes, you can! make sure to use either double quotes to wrap your values or escape the single quotes using &#39; .


2 Answers

To format the output, you can use the pre element.

Howver, you will still need to turn the special characters < > ' " & into their HTML entities &lt; &gt; and so on so the HTML tags turn up in clear text and don't get rendered by the browser.

If you can use PHP, there is htmlspecialchars() for that. Every server-side scripting language has an equivalent of it.

In JavaScript, setting the innerText property of the pre container leads to the characters being displayed literally and not as interpreted HTML.

If you want to do it manually, this is what you need to convert:

& to &amp;
> to &gt;
< to &lt;
" to &quot;
' to &#039

source

like image 111
Pekka Avatar answered Oct 14 '22 04:10

Pekka


I think you're asking for the <pre> tag for preformatted text.

Everything that goes inside the pre tag it's not interpreted.

Try this on a browser:

<pre>
&lt;img src="whatever" /&gt;
&lt;othertag&gt;whatever&lt;/otherta&gt;
</pre>

EDIT: As Pekka pointed out, for HTML tags, symbols must be converted to their HTML entities.

like image 22
CastleDweller Avatar answered Oct 14 '22 05:10

CastleDweller