HTML URL Encoding

Subject: html

šŸ”— HTML URL Encoding

URL Encoding, also known as percent encoding, is used to convert characters into a format that can be safely transmitted over the internet through a URL.


ā“ What Is URL Encoding?

URLs can only use the ASCII character set. Characters outside this range or reserved characters (like spaces or @, #, %) must be encoded.

This is done by replacing such characters with a percent sign (%) followed by two hexadecimal digits representing their ASCII value.

āŒ Characters That Require Encoding

  • Spaces ( )
  • Symbols (@, #, %, &, ?, etc.)
  • Non-ASCII characters (Ć©, Ʊ, āœ“, etc.)

āœ… Example:


šŸ”£ Common Encoded Characters

CharacterEncoded Form
Space%20
#%23
%%25
&%26
=%3D
?%3F

šŸ•µļø When Is URL Encoding Used?

  • šŸ” Query Strings: ?name=John Doe → ?name=John%20Doe
  • šŸ“© Form Submissions (GET method)
  • šŸ“ Path Parameters
  • šŸ“§ Email Links or Redirect URLs

šŸ“ Example: HTML Form with URL Encoding

šŸ“Œ Resulting URL on submission:

The space is encoded as %20 automatically by the browser.


šŸ“Œ Key Takeaway

  • URL encoding ensures special and non-ASCII characters are safely transmitted.
  • Characters are replaced with % followed by their ASCII hex value.
  • Especially important for query strings, form data, and dynamic URLs.
  • 🧠 Browsers automatically handle this encoding in form submissions and <a> links.