Why are HTML character entities necessary?

后端 未结 6 1187
挽巷
挽巷 2021-01-04 18:30

Why are HTML character entities necessary? What good are they? I don\'t see the point.

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 19:02

    "1 < 2" lets you put "1 < 2" in your page.

    Long answer:

    Since HTML uses '<' to open tags, you can't just type '<' if you want that as text. Therefore, you have to have a way to say "I want the text < in my page". Whoever designed HTML (or, actually SGML, HTML's predecessor) decided to use '&something;', so you can also put things like non-breaking space: ' ' (spaces that are not collapsed or allow a line break). Of course, now you need to have a way to say '&', so you get '&'...

提交回复
热议问题