Putting tags in paragraphs

< p > < div > < p >
(Weird spacing because it makes the text disappear when I post it)

If I wanted to create a paragraph that writes “< div >”, how would I prevent it from thinking it’s an actual < div >? I vaguely remember something from JS where you add a backslash and you can use quotation marks, but that doesn’t seem to work here (unless I’m doing it wrong).

3 Likes

Given the special meaning of < and > within html, we need a special trick if we want to display them:

&gt;
&lt;

there you go, the characters are now escaped and should be displayed on page. Prove:
> <

5 Likes

To expand on @stetim94’s correct answer and address the part you

vaguely remember

where you add a backslash and you can use quotation marks

This is called escaping. The backslash escapes the characters (as stetim said), which results in them being rendered properly, e.g;

console.log(""hello"");

=> Uncaught SyntaxError: missing ) after argument list

can be solved with a couple of backslashes;

console.log("\"hello\"");

=> "hello"

You can read more here.

4 Likes