Menu DaniWeb
Log In Sign Up
  • Read
  • Contribute
  • Meet
  1. Forums
  2. Digital Media
  3. UI / UX Design
  4. Code Snippet Repository
  5. Reusable Code Snippet

Adding Page Anchors (links on a site that go to other places on site)

21 Years Ago .:.wolvie.:. 0 Tallied Votes 142 Views Share

Page Anchors... Simple enough...two easy little codes to plug in and your ready to go! Come learn how!

user-interface web-design
To make a page anchor, go to the page 
you want to put it on, decide where you 
want it, THE LINK YOU CLICK ON TO JUMP
 TO OTHER PARTS OF THE PAGE,, center, 
left, etc., and plug in this code:

<a href="#codeword">whatever words you want to use</A>

Then after you've done that, decide where 
you want to make the page go to 
automaticly when you click on it. Say i
 wanted one to go to the top of a page,
 then I'd put in this next code BEFORE all 
of my text on the whole page, that way, 
it goes to the TOP and nothing else ;)

<A name="codeword"></A>

After that you may want to test it out and
 see how it works!
About the Author
Member Avatar for .:.wolvie.:.
.:.wolvie.:. 0 Newbie Poster

Dani AI

Generated 9 Months Ago

Good, simple intro from — the classic named-anchor idea is covered, but a few modern, practical updates stop common problems (hidden targets under fixed headers, poor keyboard/screen‑reader behaviour, and obsolete attributes).

Use the id attribute on the actual target element instead of empty legacy anchors. Any element can be targeted; keeping IDs on headings keeps markup semantic and easier to maintain:

<h2 id="features">Features</h2>

Links reference that fragment with #features. The name attribute on <a> is considered obsolete in modern HTML; see MDN: a element for details.

Smooth scrolling and fixed-header offsets prevent awkward jumps. A small CSS approach works in current browsers:

html { scroll-behavior: smooth; }
h2 { scroll-margin-top: 72px; } /* leave space for a fixed nav */

Accessibility and focus handling matter for keyboard and screen‑reader users. After programmatic jumps, set focus to the target so assistive tech announces context:

const t = document.getElementById('features');
if (t) { t.tabIndex = -1; t.focus(); }

Keep IDs unique, short, and without spaces or odd punctuation to avoid CSS/URL escaping headaches. Test fragments cross-page (URL#id) and on mobile. For more info on smooth scrolling and offsets, see MDN: scroll-behavior and MDN: scroll-margin-top.

Be the first to reply
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Sign Up — It's Free!
Recommended Topics
  • Member Avatar Web Design Board 11
  • Member Avatar Link to page in page 7
  • Member Avatar HTML Tables vs CSS & divs - examples/help 7
  • Member Avatar To underline links or not to underline links 19
  • Member Avatar Layout change by date? 5
  • Member Avatar How do i set a page as a Home Page 6
  • Member Avatar how to make a page dynamic like yahoo 6
  • Member Avatar Amazing Website Designs - How do they do this? 75
  • Member Avatar Simple css templates 21
  • Member Avatar iframe help 4
  • Member Avatar Registrar transfer problem - who is my registrar?! 8
  • Member Avatar how do i make a website? 4
  • Member Avatar Two menus to have different colour attributes 2
  • Member Avatar Another Webmaster in the Works 10
  • Member Avatar User Interface Designer 4
  • Member Avatar Avoid A Color Disaster! 7
  • Member Avatar How to make a drop down menu. 4
  • Member Avatar Need A Small Favor 5
  • Member Avatar Bookmark function in mozilla firefox 3
  • Member Avatar Making a random playlist? 3
Not what you need?

Reach out to all the awesome people in our ui / ux design community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.

Start New Topic
Topics Feed
Reply to this Topic
Edit Preview

Share Post

Insert Code Block

  • Forums
  • Forum Index
  • Hardware & Software
  • Programming
  • Digital Media
  • Community Center
  • Recent
  • Recommended Topics
  • Newest Topics
  • Latest Topics
  • Latest Posts
  • Latest Comments
  • Top Tags
  • Tools
  • Writing
    • Start New Topic
    • Markdown Syntax
    • Newsletter Archive
  • Social
    • Top Members
    • Meet People
  • APIs
    • Connect API
    • Forum API Docs
    • Topics Feed
  • Resources
  • Community Rules
  • DaniWeb Premium
  • FAQ
  • About Us
  • Advertise
  • Contact Us
  • Legal
  • Terms of Service
  • Privacy Policy
© 2026 DaniWeb® LLC
© 2026 DaniWeb® LLC
  • FAQ
  • About Us
  • Advertise
  • Contact Us
  • Terms of Service
  • Privacy Policy