After some digging on the internet I was unable to find a good answer to which characters I may use for URL fragment. I'm writing a javascript-script that will take advantage of URL fragments.
I wanted to make the URL eye-friendly by not having it looking too complicated. So I was wondering if I could use characters like ':, ?, & or !' in the URL fragment and still have it valid.
My URL fragment should contain the following values:
A fragment is an internal page reference, sometimes called a named anchor. It usually appears at the end of a URL and begins with a hash (#) character followed by an identifier. It refers to a section within a web page. In HTML documents, the browser looks for an anchor tag with a name attribute matching the fragment.
A URL cannot have more than one fragment. URL parameters are passed in key-value pairs. URL fragments comprise just a string of text after the hash (#).
In a URL, a hash mark, number sign, or pound sign ( # ) points a browser to a specific spot in a page or website. It is used to separate the URI of an object from a fragment identifier. When you use a URL with a # , it doesn't always go to the correct part of the page or website.
Fragment identifiers are not sent to the server. The hash fragment is used by the browser to link to elements within the same page.
The fragment identifier component can contain:
0
- 9
a
- z
A
- Z
?
/
:
@
-
.
_
~
!
$
&
'
(
)
*
+
,
;
=
%
followed by two hexadecimal digits)The URI standard is STD 66, which currently maps to RFC 3986.
In this document, you’ll find everything you need to know.
The fragment identifier component is defined in section 3.5:
fragment = *( pchar / "/" / "?" )
This means that the fragment can contain nothing or (any combination of)
/
?
pchar
Refer to the appendix A. to see how pchar is defined:
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
So this adds
:
@
unreserved
Now check how unreserved is defined:
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
This adds
-
.
_
~
ALPHA
and DIGIT
Check how ALPHA and DIGIT are defined. They are not listed in the appendix, because they are from the core ABNF rules, as is explained in section 1.3:
ALPHA (letters), […] DIGIT (decimal digits) […]
So this adds
a
-z
, A
-Z
0
-9
pct-encoded
Check how pct-encoded is defined:
pct-encoded = "%" HEXDIG HEXDIG
This allows for any percent-encoded character.
sub-delims
Check how sub-delims is defined:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
This adds
!
$
&
'
(
)
*
+
,
;
=
It's a bit tricky to find the valid characters, but the file commented above does contain the information if you read deep enough.
The available characters are as follow:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With