πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

HTML Encoding

Web Foundations🟒 Free Lesson

Advertisement

HTML Encoding

Character encoding, special characters, entities, and internationalization.

Overview

Proper encoding ensures text displays correctly across browsers and devices.

Key Concepts

  • UTF-8 β€” Universal character encoding
  • HTML Entities β€” Special character codes
  • Named Entities β€” &, <, >
  • Numeric Entities β€” A for 'A'
  • Escaping β€” Prevent XSS attacks

Code Examples

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML Encoding</title>
</head>
<body>
  
  <p>Ampersand: &amp;</p>
  <p>Less than: &lt;</p>
  <p>Greater than: &gt;</p>
  <p>Quote: &quot;</p>
  <p>Non-breaking space: &nbsp;</p>
  
  
  <p>Euro: &euro;</p>
  <p>Pound: &pound;</p>
  <p>Copyright: &copy;</p>
  <p>Registered: &reg;</p>
  <p>Trademark: &trade;</p>
  
  
  <p>Plus-minus: &plusmn;</p>
  <p>Multiplication: &times;</p>
  <p>Division: &divide;</p>
  
  
  <p>Left arrow: &larr;</p>
  <p>Right arrow: &rarr;</p>
  
  
  <div id="userContent"></div>
  
  <script>
  // Properly escape HTML
  function escapeHtml(text) {
    const div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
  }
  
  // XSS prevention
  const userInput = '<script>alert("XSS")<\/script>';
  const safeContent = escapeHtml(userInput);
  document.getElementById('userContent').textContent = safeContent;
  
  // Encoding/decoding
  const encoded = encodeURIComponent('Hello World!');
  const decoded = decodeURIComponent(encoded);
  
  // Base64 encoding
  const base64 = btoa('Hello World!');
  const decoded64 = atob(base64);
  </script>
</body>
</html>

Practice

Build a text encoder/decoder tool with HTML entity support.

⭐

Premium Content

HTML Encoding

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement