HTML entities are special codes (also known as character entities or escape sequences) that represent characters that have special meaning in HTML, such as angle brackets (<
and >
), ampersands (&
), quotes ("
and '
), and other special characters like accented letters or mathematical symbols.
For example, if you want to display the less than sign (<) in your HTML document, you would write <
instead of <
. Similarly, to display the copyright symbol ©, you would use ©
.
HTML entities are useful when you want to display characters that cannot be typed on a keyboard, or if you want to display characters in a way that won't be misinterpreted by the browser.
Common entities
Here's a table of commonly used special symbols in HTML with their corresponding descriptions and HTML escape codes or names:
Symbol | Description | Escape Code/Name |
Non-breaking space | | |
& | Ampersand | & |
< | Less than | < |
\> | Greater than | > |
" | Double quotation mark | " or " |
' | Single quotation mark (apostrophe) | ' or ' |
¢ | Cent sign | ¢ or ¢ |
£ | Pound sterling sign | £ or £ |
¥ | Yen sign | ¥ or ¥ |
€ | Euro sign | € or € |
© | Copyright sign | © or © |
® | Registered trademark sign | ® or ® |
™ | Trademark sign | ™ or ™ |
§ | Section sign | § or § |
Note: In addition to these escape codes, you can also use numeric character references (such as "
or €
) to represent special characters in HTML.
Using quotes
In HTML, you should always use double quotes to surround the value of the class
and id
attributes within an element, and more generally within any attribute. However, when it comes to the content of an HTML element, you can use both double quotes and single quotes without the need for escaping any of the quotes.
For example, consider the following paragraph HTML tag:
<p>This is an example using "double quotes" and 'single quotes'.</p>
In the above example, we have used both double quotes and single quotes within the content of the p
element without using any escaping characters.
This flexibility can be useful when you want to include quoted text as part of the content within an HTML element, such as in a block of text or in an unordered list item.
It's worth noting that it's always a good practice to properly escape any characters that have a special meaning in HTML and use entities when necessary.
Expressions
HTML entities can be used to represent special characters, symbols, and mathematical operators in HTML documents. This is particularly useful when you need to display mathematical or logical expressions on your web page.
Math symbols
Symbol | Description | Entity Name |
+ | addition | + |
- | subtraction/negation | − (‐ for negation) |
* | multiplication | × |
/ | division | ÷ |
\= | equals | = |
≠ | not equal to | ≠ |
< | less than | < |
> | greater than | > |
≤ | less than or equal to | ≤ |
≥ | greater than or equal to | ≥ |
∞ | infinity | ∞ |
∑ | sum | ∑ |
∫ | integral | ∫ |
π | pi | π |
× | Cartesian product | × |
∩ | intersection | ∩ |
∪ | union | ∪ |
∴ | therefore | ∴ |
∵ | because | ∵ |
Logic symbols
Symbol | Description | Entity Name |
¬ or ~ | negation | ¬ |
∧ | conjunction (AND) | ∧ or ∧ |
∨ | disjunction (OR) | ∨ or ∨ |
⊕ | exclusive disjunction (XOR) | ⊕ |
→ or ⇒ | implication | → or ⇒ |
↔ or ⇔ | biconditional (if and only if) | ↔ or ⇔ |
∀ | universal quantification (for all) | ∀ |
∃ | existential quantification (there exists) | ∃ |
∉ | not in | ∈ |
∈ | element of | ∉ |
Advanced symbols
Symbol | Description | |
⊤ or 1 | tautology / true | ⊤ or &True; |
⊥ or 0 | contradiction / false | ⊥ or &False; |
⊢ | entails (provable) | ⊢ or &proves; |
⊨ | models (satisfies) | ⊨ or ⊧ |
These symbols can be used in HTML code by placing them between the '&' symbol and a semi-colon. For example, you could use ∧
to represent the conjunction symbol ∧. So, if you wanted to represent the statement "p ∧ ¬q", you could use the following HTML code:
p ∧ ¬q
This would output "p ∧ ¬q" on your webpage.
These entities can be used within HTML tags that are used to display text, such as the p
tag or span
tag. For example, you can use the ≤
entity in an HTML paragraph to represent the less than or equal to symbol:
<p>x ≤ y</p>
This will output the text "x ≤ y" on the web page.
Similarly, you can use the ∈
entity in an HTML unordered list item to represent the element of symbol:
<ul>
<li>∈ set A</li>
<li>∉ set B</li>
</ul>
This will output an unordered list with the text "∈ set A" and "∉ set B".
Overall, using HTML entities to represent math and logic expressions can make your web pages more readable and professional-looking.
Disclaim: This article was created with ChatGPT