Does an anchor tag come before the query string or after?

I am unclear if an anchor tag should come before a query string or after.

http://www.domain.com/search?query=hello#name

or

http://www.domain.com/search#name?query=hello

Or does it matter?


Best practice is to append the named anchor at the end. The technical name is a fragment identifier, and the syntax is in RFC 3986.

The RFC section is here: https://www.rfc-editor.org/rfc/rfc3986#section-4.1

relative-ref = relative-part [ "?" query ] [ "#" fragment ]

Wikipedia actually covers it well:

The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document