HTML: Set anchor - how it works
HTML is used to define or program the structure of web pages. In the process, the web pages are created in table form. Since HTML5 you can use several new features. However, anchors already existed before, these form the start and end point of a hyperlink.
How to set an anchor in HTML
- If you want to refer to a specific heading in your HTML document, you can give that heading a specific ID.
- Use the command <h2 id="ichBinEinAnkername"> heading 2 </h2> to set an anchor in the second heading "h2".
- Of course you can choose the "id" arbitrarily. This does not have to be "ichBinEinAnkername".
- In older HTML versions, the structure is slightly different: (<h2><a name="ichBinEinAnkername"> heading 2 </a></h2>).
- Now you can link directly to this anchor in the same HTML document or another. The browser will then jump to that location on the web page.
- In the same document, use <a href="#ichBinEinAnkername"> linkname </a>.
- In another HTML document, use <a href="url#ichBinEinAnkername> linkname </a>.
- Replace url with the appropriate path to the HTML document. If the other document is in the same folder, "documentname.html" is enough, otherwise you have to take the correct path, for example "www.MeineWebseite.de/MeinDokument.html".