this post was submitted on 12 Aug 2023
83 points (97.7% liked)

Explain Like I'm Five

14306 readers
597 users here now

Simplifying Complexity, One Answer at a Time!

Rules

  1. Be respectful and inclusive.
  2. No harassment, hate speech, or trolling.
  3. Engage in constructive discussions.
  4. Share relevant content.
  5. Follow guidelines and moderators' instructions.
  6. Use appropriate language and tone.
  7. Report violations.
  8. Foster a continuous learning environment.

founded 1 year ago
MODERATORS
 

I feel like whenever I see the ampersand on this website, it’s followed with “amp;”. I’ve noticed it other places on the internet also. Why does this happen? Is it some programming thing?

Just for a test: &

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

The reason is because a programmer at some point decide that & should indicate the start of a special symbol in HTML. In programming parlance this is a means of “escaping” characters which are reserved.

For example, in HTML, things look something like this:

<p>Hello, World!</p>

The p in the less than and greater symbol symbols means “paragraph” where the ending version with the slash means “the paragraph is done”.

However, there’s a problem. What if you wanted to actually type out <p> to the end-user and have it not be treated as HTML? You use the ampersand syntax to write &lt; by using &lt; and > by using >.

</p><p>&lt;p></p>

Yet another problem: If we use &amp; as a special character in HTML, we also need a way to display it—the answer is &amp;