Skip to main content
D
HTML
HTML URL Encode

HTML URL Encode

HTML URL encoding translates unsafe characters in web addresses.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

URLs only accept specific ASCII characters over the internet. URL encoding replaces unsafe characters with a percent sign and hexadecimal digits. Browsers automatically encode URLs when submitting forms.

Syntax

Syntax
1<!-- url encode syntax -->
2<a href="/search?q=hello%20world">Search</a>

Example

Example
1<!-- this encodes a URL -->
2<!DOCTYPE html>
3<html lang="en">
4  <head>
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <title>URL Encode</title>
8  </head>
9  <body>
10    <a href="/login?user=john%20doe">Login John Doe</a>
11  </body>
12</html>

Try it Yourself

Hands-on Practice
Modify the code below to see how it affects the output. This is the best way to learn!
Interactive Editor
1234567891011121314151617181920
Live Preview

Key Points

  • URLs require safe ASCII characters.
  • Encoding replaces spaces with `%20`.
  • Forms encode data upon submission.
  • Unsafe symbols break URL navigation.

Up Next

Continue your journey with the next topic.

Go to HTML vs XHTML