How to quote in HTML (not blockquote)?

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

A Tag example: <a href="your_url"></a> Image Tag example: <img...> 
+4
source share
3 answers

I think you are requesting a <pre> for preformatted text.

Everything included in the pre tag is not interpreted.

Try this in a browser:

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

EDIT: As Pekka noted, for HTML tags, characters must be converted to their HTML objects.

+2
source

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

However, you still have to turn the special < > ' " & characters into your HTML objects &lt; &gt; etc., so that the HTML tags are displayed in clear text and not displayed by the browser.

If you can use PHP , there are htmlspecialchars () for this. Each server-side scripting language has an equivalent.

In JavaScript, setting the innerText property in the pre container causes characters to appear literally, rather than as interpreted HTML.

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

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

a source

+5
source

You can use a combination of <pre> and <code> . The <pre> formats everything inside it, as shown in the source code (useful for showing large blocks of the source), and the <code> used for in-line code formatting (similar to how the tags in this answer are formatted). In addition, something inside the <code> tags needs to be converted to special HTML characters (e.g.> and and lt, for example).

+1
source

Source: https://habr.com/ru/post/1301006/


All Articles