Nate
Nate

Reputation: 28334

Is there any reason to use HTML entities over the characters themselves?

For example, suppose I want to put an en dash in my page title, like this:

Home – My Site

Is there any reason to use – over just putting the character in my HTML file?

Upvotes: 4

Views: 1134

Answers (4)

user4639281
user4639281

Reputation:

If you use the less than (<) or greater than (>) signs in your text, the browser might mix them with tags. W3Schools.com

The only other HTML entities I would probably ever use would be &nbsp; and &amp; unless a specific issue came about.

Upvotes: 1

Jimmie Tyrrell
Jimmie Tyrrell

Reputation: 1658

It is definitely needed if you want to render characters that will mess up the HTML parser (< and >, and the & itself).

If you set the character set to UTF-8, then you can use other raw UTF8 characters.

<meta charset='utf-8'>

However some older browsers don't understand this tag, so they might not render UTF-8 characters properly.

I also wanted to point out - HTML entities are sometimes used to tell the browser to render a concept, rather than a specific character. Some browsers prefer to render entities in a more readable way than a Unicode character, for example Lynx renders &trade; as (tm) instead of

Upvotes: 4

user2182349
user2182349

Reputation: 9782

If an HTML entity exists for the character you want to use, you should use the HTML entity. That ensures it displays as intended.

http://www.danshort.com/HTMLentities/index.php?w=latin

Upvotes: 0

caustic
caustic

Reputation: 585

yes. some browsers and operating systems don't like it when you use the actual entity as it is... occasionally when typing a dash on a Mac it will just scramble or look like a void square on a Windows machine. its just safer to use the entity :D

Upvotes: -1

Related Questions