Loading...

HTML Entities

Some characters are special in HTML. If you type a raw < in ordinary page text, the browser may think a tag is starting. If you type a raw &, it may think an entity is starting. Character entities are safe codes that display those symbols as visible text instead of confusing the parser.

What is an HTML entity?

An HTML entity is a coded way to write a character in markup. Most named entities start with & and end with ;. The browser replaces the code with the real character when it renders the page. You need entities most often for characters that HTML already uses as markup syntax, and sometimes for symbols that are awkward to type.

Direct answer

Use entities when a character would be unsafe or unclear as raw text. Remember these first: &lt; for <, &gt; for >, &amp; for &, and &nbsp; for a non-breaking space. Always finish a named entity with ;. Use them in paragraphs, and inside HTML-teaching examples, whenever the raw character would break or misread the document.

Common entities at a glance

📊 Common entities

Entity Shows Use
&amp;lt; less-than Safer than a raw opening angle bracket in text
&amp;gt; greater-than Safer closing angle bracket in text
&amp;amp; ampersand When you need an and-sign as text
&amp;nbsp; non-breaking space Keep words or a label and number on one line
&amp;quot; quotation mark Quote character when needed
&amp;copy; copyright Copyright symbol

Reserved characters in sentences

When you teach or mention tags in a normal paragraph, show them with entities so they stay text.

Entities in a sentence

html
HTML Code
<p>Write &lt;p&gt; for a paragraph tag, and use &amp; between names: Tom &amp; Jerry.</p>

Reading the sample

  • &lt;p&gt; displays as the characters <p> without creating a paragraph element there
  • Tom &amp; Jerry displays as Tom & Jerry
  • A raw & without a valid entity can cause parsing problems
  • Normal letters like p and Jerry do not need entities

Non-breaking spaces

&nbsp; is a space that browsers should not use as a soft wrap point between the parts it joins. It is useful for keeping a short label with a number, or words you want to stay together. Do not sprinkle it everywhere as a layout tool — prefer normal spaces and CSS for real design.

Non-breaking space

html
HTML Code
<p>Chapter&nbsp;4 stays on one line more reliably than a normal space might.</p>

Named entities vs typing the symbol

For many symbols you can paste the real character if your file is saved as UTF-8 (see the Charset session later). Entities remain especially important for <, >, and & because those characters are part of HTML syntax. Learning the common named forms makes teaching pages and examples reliable across editors.

Practice in your editor

  1. Write a paragraph that shows the text <div> using &lt; and &gt;.
  2. Add a line with AT&T written safely using &amp;.
  3. Use &nbsp; between a short title and a number you do not want split across lines.
  4. Open the page and confirm the symbols look correct.
  5. View source and find the entity codes — compare source vs rendered text.
  6. Intentionally forget a semicolon on one entity, reload, notice the odd result, then fix it.

Mistakes that break entities

  • Forgetting ; at the end of an entity
  • Writing a lone & in text that is not a complete entity (prefer &amp; when you mean an ampersand)
  • Encoding ordinary letters and words that never needed entities
  • Using &nbsp; as a substitute for margin and layout instead of learning CSS spacing
  • Mixing up &lt; and &gt; when showing tag examples

Summary

  • Entities display reserved or special characters safely in HTML text
  • Start with &lt;, &gt;, &amp;, and &nbsp;
  • Named entities begin with & and end with ;
  • Encode angle brackets and ampersands when they should appear as text
  • Do not entity-encode normal prose letters without a reason
  • Entities are especially handy when an HTML page teaches HTML

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
7
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top