HTML URL Encode
Charset decides how the HTML file turns bytes into letters. URL encoding (percent-encoding) is a different problem: how characters travel safely inside a URL — in links, redirects, and form query data — without breaking the URL’s own structure. Spaces, non-ASCII letters, and reserved symbols often need a % + hex form so browsers and servers agree on the meaning.
What URL encoding is
A URL has reserved characters that structure the address: ? starts a query, & separates pairs, = joins names to values, # starts a fragment. If those characters appear as data inside a value, they must be encoded so they are not mistaken for structure. Unsafe characters such as spaces are also encoded for reliable transport.
Direct answer
URL encoding replaces a character with % followed by two hexadecimal digits. The classic example: a space becomes %20. Many browsers and HTML forms encode query values automatically when you submit. You still need the idea when you hand-write href query strings, debug a broken link, or read an address bar full of percent-codes.
Common percent encodings
📊 Common percent encodings
| Character | Encoded | Note |
|---|---|---|
| space | %20 | Very common in query strings |
| # | %23 | # otherwise starts a fragment |
| & | %26 | & separates query pairs |
| = | %3D | = separates name and value |
| ? | %3F | ? starts the query string |
| / | %2F | Slash inside a value may need encoding |
Encoded query in a link
Hand-writing a search query with a space is the clearest beginner demo. Encode the space in the value; leave the structural ? and = alone.
Link with an encoded space in the query
html<p>
<a href="search.html?q=html%20links">Search for html links</a>
</p>
Reading the sample
search.htmlis the path; keep path filenames simple when you control them?q=starts a query parameter namedqhtml%20linksis the value “html links” with a space encoded as%20- The visible link text can stay human-readable; encoding belongs in the URL
Prefer clean filenames; encode values
Encoding an entire page filename that contains spaces is awkward for everyone. Prefer my-page.html over my page.html. Use percent-encoding mainly for query values and special characters inside URLs you must assemble by hand.
Clean path versus encoded query value
html<!-- Prefer a clean path -->
<a href="my-page.html">My page</a>
<!-- Encode spaces inside query values when needed -->
<a href="results.html?topic=url%20encode">URL encode results</a>
Forms and browsers often help
When a user submits an HTML form with method="get", browsers typically encode field values into the query string for you. That does not remove the need to understand %20 when you read logs, share links, or write href by hand. Knowing the pattern makes debugging faster.
Not the same as HTML entities
In HTML text, & is an entity for the ampersand character. In a URL, an ampersand that is data may appear as %26. Different tools, different contexts. Likewise, file charset UTF-8 is about decoding the .html file — it does not replace percent-encoding inside URLs.
Non-ASCII in URLs (beginner note)
Letters outside basic ASCII may appear as longer percent-sequences in real addresses. You do not need to memorize those charts in this session. Remember the rule: when a character is unsafe or reserved as data, percent-encoding is how URLs carry it. For learning pages, keep demo queries in simple Latin plus %20 until you are comfortable.
Practice in your editor
- Create a link whose
hrefincludes a query like?q=hello%20world. - Open the link and observe the address bar.
- Change
%20to a raw space in the source, reload, and compare how the browser normalizes or breaks the URL. - Rename a practice file to use hyphens instead of spaces and update links accordingly.
- Write one query value that would need
%26if an ampersand were part of the data — then confirm you did not encode the structural&between parameters.
Easy mistakes
- Pasting raw spaces into URLs in code without checking the result
- Percent-encoding the
https://scheme or the whole structural skeleton by mistake - Confusing HTML entities (
&) with URL codes (%26) - Putting spaces in every filename and hoping encoding will save navigation forever
- Encoding structural
?/&/=that should stay as URL syntax between parts
Summary
- URL encoding uses
%plus two hex digits (space →%20) - Reserved and unsafe characters need encoding when they are data
- Prefer simple filenames; encode query values when you hand-write them
- Forms and browsers often encode automatically on submit
- Percent-encoding is not the same job as HTML entities or file charset
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 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