Do you choose effective anchor names?

Updated by Tiago Araújo [SSW] 1 year ago. See history

123
<introEmbed body={<> It is often that developers find themselves using the incorrect/inefficient anchor names. </>} />

According to W3C, anchor names must observe the following rules:

  • Anchor names must be unique within a document
  • Begin with a letter (A-Z, a-z) and may be followed by any number of letters, digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
  • Don't add spacings - When you are defining an anchor name, make sure there are no spaces within the name
  • Anchor name cannot start with #

These are the things you should consider when creating an anchor link:

  • Make it meaningful - When you are sending the URL by email it helps indicate what you are talking about
  • Avoid list numbers - They often change. An anchor like #13 becomes incorrect when the order changes
  • Know they are case sensitive - #usergroups is not the same as #UserGroups. Always check your links and anchor names are identical, matching the capitalization
<a name="1st section"></a>

❌ Figure: Bad example - Beginning with a number, spaces within, and meaningless anchor name

<a name="get-started"></a>

✅ Figure: Good example - Beginning with a letter, no spaces, and a meaningful anchor name

Acknowledgements

Adam Cogan
Tiago Araujo
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star