What are the benefits of using HTML entities in my code

Hi guys,

after finishing the HTML entities algorithm scripting challenge I just wanted to ask the question "How important is it to use HTML entities when writing html code?

I mean, if I write a sentence <h1>my cat & my dog</h1> what are the consequences, if any, if I write
<h1>my cat &amp; my dog</h1>

Does it really matter?

Hi, @JackEdwardLyons. Entities are used to represent characters in HTML that can’t be easily typed on a keyboard (like the copyright mark, math symbols, etc.) , or characters that have special meaning in HTML code (like the < or > symbols, and also &).

Hi there,

thanks for the response… I understand, but I suppose what I was trying to get at is the question --> are there any semantic penalties or things that could go wrong if I don’t use them all the time ie.) if I write & and not &amp; in my html…?

Using &amp; is recommended, according to what I’ve read.

Authors should use “&” (ASCII decimal 38) instead of “&” to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use “&” in attribute values since character references are allowed within CDATA attribute values.

I found that here:

1 Like

There are situations where special characters can confuse a parsing engine for a particular framework if they aren’t encoded. One example - Let’s say you made an awesome HTML page that makes use of ‘@’ a lot. Perhaps you have a big list of emails in your web page. Then let’s say you need to convert that web page to CSHTML to make a dynamic website. CSHTML files are ASP.NET files that include server side scripting within HTML. In CSHTML files, ‘@’ signifies the beginning of a C# code block, so the server will think you have C# code blocks all over the place, and it the program might fail. Now typically ASP.NET is smart and can figure out where you intended to place code, but it’s best not to test it’s limitations.

2 Likes

Thank you thats an awesome answer!!