Are Anchors Inline? The Truth Most Guides Miss

Disclosure: As an Amazon Associate, I earn from qualifying purchases. This post may contain affiliate links, which means I may receive a small commission at no extra cost to you.

I remember the first time I was trying to get a navigation menu to scroll smoothly to different sections of a webpage. It felt like wrestling an octopus. I’d read all the tutorials, copied and pasted code, and still, it was clunky, jerky, or just plain didn’t work. The exact phrase ‘are anchors inline’ kept popping up, but nobody seemed to explain why it mattered or what the actual gotchas were.

Most of what’s out there feels like it’s written by people who’ve never actually done it, just read about it. They spit out definitions and code snippets, but miss the practical, hands-on stuff. You end up clicking around, frustrated, wondering if you’re the only one struggling.

Let’s cut to the chase: are anchors inline? Not always, and that’s often the root of your headaches. Understanding this is key to making your web pages behave.

Table of Contents show

What the Heck Does ‘inline’ Even Mean for Anchors?

So, you’re building a website, maybe a simple landing page or a more complex blog, and you want those nifty “scroll to section” links. You’ve probably seen them everywhere – click a link in a table of contents, and bam, you’re at the relevant part of the page. You’ve heard the term “anchor” or “anchor link,” and you’re trying to figure out if these anchors need to be “inline” to work. The honest answer is: it’s less about whether the anchor itself is inline and more about how the HTML elements you’re linking to are structured and how you’re implementing the links. Confusing, right? That’s why I’m here to clear it up.

In HTML, elements are generally classified as either block-level or inline. Block-level elements, like headings (h1, h2, etc.), paragraphs (p), and divs (div), typically start on a new line and take up the full width available. Inline elements, like spans (span), links (a), and images (img), flow with the text and only take up as much space as they need. When we talk about anchors, we’re usually referring to the `` tag, which is inherently an inline element. So, in that sense, yes, the link element itself is inline.

The problem arises when you try to link to something that isn’t set up correctly to receive that link. If you’re trying to link to a specific piece of content within another block-level element, and that content doesn’t have a unique identifier (an `id` attribute), the browser doesn’t know where to jump. You can’t just slap an `id` on a random word in a paragraph and expect magic. The `id` needs to be on the element you want to scroll to. For example, if you want to scroll to a subheading, the `id` should be on that `

` Tag, Not on the `` You Might Wrap Around a Word in the Preceding Paragraph.

my First Real Project Involving Scroll-to Links Was a Disaster Because I Kept Trying to Put Ids on Random Words. I’d Have a Paragraph Like, “this Is an Important point About Our Product.” Then, My Nav Link Would Be `read the Important Point`. Guess What? It Barely Worked, If at All. The Browser Was Confused. It Wanted to Go to an Element with the Id, Not Just a Piece of Text within an Element.

the Important Takeaway Here Is That the `id` Attribute, Which Is What Your `` Tag’s `href` Attribute Points to (e.G., `href=”#my-Section-Id”`), Needs to Be Attached to a Specific Html Element That the Browser Can Target. This Element Is Often a Block-Level Element Like a `

`, `
`, or a Heading Tag (`

`, `

`, Etc.) That You Want to Scroll Into View. If You’re Trying to Make an Anchor Link Work, and You’re Wondering If Your Anchors Are Inline, Stop Thinking About the `` Tag’s Inline Nature and Start Thinking About the `id` You’re Linking to. Is That `id` on a Proper Target Element?

the Real Reason Your Scroll Links Are Jerky

okay, So You’ve Got Your `id` Attributes in Place. You’ve Got Your `` Tags Pointing to Them. Yet, When You Click, It’s Like the Page Is Having a Seizure. It Jolts, It Might Bounce, or It Just Doesn’t Feel Smooth. Why? Because Just Having the Right Html Structure Isn’t the Whole Story. The Way You’re implementing the Scroll Behavior Is Often the Culprit, and It Has Little to Do with Whether Anchors Are Inline and Everything to Do with How the Browser Handles the Jump.

historically, the Default Behavior for Clicking an Anchor Link (``) Was a Hard, Instant Jump. No Animation, No Fade-in, Just snap. This Is What Most Browsers Still Do by Default If You Don’t Tell Them Otherwise. This Jarring Jump Is What Makes People Think the Anchors Themselves Are Broken or That There’s Some Arcane Rule About Them Needing to Be Inline in a Specific Way.

to Get That Smooth Scrolling Effect That Feels Polished and Professional, You Need to Intervene. The Most Common Way to Do This Is with Css or Javascript. Using Css, You Can Apply a Property Called `scroll-Behavior: Smooth;` to the Element That Is Doing the Scrolling – Typically the “ or `

` Element. It’s Ridiculously Simple and Effective:

html {
  Scroll-Behavior: Smooth;
}

when You Add This to Your Stylesheet, Any Anchor Link on the Page That Targets an Element within That “ or `

` Will Automatically Animate Its Scroll. It’s a Big Deal and Takes About Five Seconds to Implement. I’ve Seen So Many Developers Spend Hours on Javascript for This When a Single Line of Css Would Have Done the Trick.

if You Need More Control, Like Animating to a Specific Position relative to the Target Element, or If You’re Dealing with Older Browsers That Don’t Support `scroll-Behavior: Smooth;` Perfectly, Then Javascript Becomes Necessary. Libraries Like Jquery Used to Be the Go-to for This, but Modern Javascript Can Achieve It Without Any External Dependencies. You’d Typically Add an Event Listener to Your Links, Prevent the Default Jump, Calculate the Position of the Target Element, and Then Use `window.Scrollto()` or `element.Scrollintoview({ Behavior: ‘smooth’ })` to Animate the Scroll. (See Also: Can Concrete Anchors Be Used In Brick )

my Own “aha!” Moment Came When I Was Building a Portfolio Site for a Photographer. The Client insisted on Smooth Scrolling, and I Was Banging My Head Against the Wall with Clunky Javascript. I Finally Stumbled Upon `scroll-Behavior: Smooth;` in a Css Spec. I Felt Like an Idiot for Not Knowing It, but Also Ecstatic Because It Solved the Problem So Cleanly. It Truly Highlights How Often the Simplest Solution Is Overlooked When You’re Deep in the Technical Weeds, Wondering About Things Like Whether Anchors Are Inline.

so, If Your Links Are Jumping Instead of Smoothly Gliding, Don’t Blame the Anchors or Their Inline Status. Blame the Lack of `scroll-Behavior: Smooth;` in Your Css, or an Inefficient Javascript Implementation. This Is Where Most People Get Tripped Up, and It Has Nothing to Do with the Fundamental Nature of Anchor Tags Themselves.

what to Look for: The Anatomy of a Working Anchor

alright, Let’s Get Practical. You Want Your Anchor Links to Work Flawlessly. This Means Understanding the Two Key Components: The Link Itself (the `` Tag) and the Destination (the Element with the `id`). If You Nail These, You’re 90% of the Way There, Regardless of Whether Anchors Are Inline in the Abstract Sense.

first, the Link. It’s an `` Tag, and Its `href` Attribute Is What Tells the Browser Where to Go. For Internal Page Links, This `href` Attribute Starts with a Hash Symbol (`#`) Followed by the `id` of the Element You Want to Link to. For Example: `go to Section Two`. Simple Enough. You Can Put This `` Tag Anywhere – Inside a Paragraph, Inside a List Item, Inside a Navigation Menu, Even Inside a Button (though That’s Less Common and Requires a Bit More Js). Its “inlineness” Doesn’t Dictate Its Functionality Here, Only Its Placement in the Flow of Text.

second, the Destination. This Is Where the `id` Attribute Comes in. You Need to Attach a Unique `id` to the Html Element That You Want the Anchor Link to Scroll to. This `id` Must Exactly Match the Value in the `href` Attribute (minus the `#`). So, for Our Example Link Above, You’d Need an Element Like This Somewhere Else on the Page:

<H2 Id="section-Two">this Is Section Two

or It Could Be a `

`:
<Div Id="section-Two">
  <P>Content for Section Two.</p>
</div>

the `id` Attribute Should Be Unique on the Page. You Can’t Have Multiple Elements with the Same `id`. If You Do, the Browser Will Only Recognize the First One It Encounters for Linking Purposes, Which Can Lead to Unpredictable Behavior.

now, a Important Point That Trips People Up: The `id` Should Ideally Be Placed on a Meaningful Element. While You can Technically Slap an `id` on a Generic `` Tag Within a Paragraph, It’s Bad Practice and Can Lead to Issues. It’s Better to Attach the `id` to the Semantic Element That Represents That Section, Like a Heading (`

`, `

`), a `
` Tag, or a `
` That Clearly Delineates That Part of Your Content. This Is Good for Accessibility and Seo, Not to Mention Making Your Own Code Easier to Understand.

let’s Look at a Quick Comparison of What Works and What Doesn’t, with My Two Cents:

scenario html Example verdict
good: Link to a Heading

about Us

about Our Company

👍 Works Perfectly. Semantic and Clean.
good: Link to a Section Div

contact Info

get in Touch…

👍 Works. Clear Division of Content.
bad: Trying to Link to Text Within a Paragraph (without a Proper Target)

this Is an important Phrase to Remember.

remember This Phrase (See Also: Can Cords Be Used To Make Anchors Climbing )

👎 Often Fails or Jumps to the Wrong Place. The `id` Needs to Be on a Block Element.
okay, but Not Ideal: Link to a Span Within a Block, but the Id Is on the Span

here’s a key Feature.

some Introductory Text.

see the Key Feature

⚠️ Might Work If the `div` Is the only Block Element, but Brittle. Best to Put the `id` on the `div` or a Heading.
good: Using Css for Smooth Scrolling

go to Section 3

section Three

🚀 Excellent. Makes the jump a smooth animation.

The key is that the `id` attribute must be on an element that the browser can easily identify as a target for scrolling. Think of it like dropping a pin on a map. You drop the pin on a specific location, not just a general area. The `id` is your pin.

Common Mistakes That Make Anchors Fail

Even with the basic structure in place, there are a few classic mistakes I see people make over and over that cause anchor links to fail, or at least behave erratically. And nope, it’s rarely about whether anchors are inline. It’s about the details.

The most frequent offender? Typos. It sounds ridiculously simple, but a single misplaced character in an `id` or in the `href` attribute will break the link. Remember, they are case-sensitive. So, `id=”MySection”` is NOT the same as `id=”mysection”`. If your link is ``, it will look for `#MySection`. If you’ve only defined it as `id=”mysection”`, the browser will just sit there, confused, and likely do nothing or jump to the top of the page.

Another common pitfall is duplicate `id` attributes. As I mentioned, `id` attributes must be unique on a single HTML page. If you accidentally copy-paste a section and forget to change its `id`, or if you have multiple elements with the exact same `id`, the browser will usually only recognize the first one it finds. This means your anchor link might jump to the wrong place, or not jump at all, because it’s confused about which of the duplicates to target.

I once spent an entire afternoon debugging a client’s site because their testimonial slider had anchors that were randomly jumping to the first testimonial, no matter what link you clicked. Turns out, the JavaScript dynamically generating the testimonial IDs had a bug, creating duplicate IDs for the second and third testimonials. The fix was simple once I spotted the duplicate IDs in the browser’s inspector, but the debugging process felt endless.

Then there’s the issue of timing. If your page loads content dynamically using JavaScript (like fetching data from an API and then displaying it), the anchor links might be set up before the content they’re supposed to link to has actually loaded. This is especially common with single-page applications (SPAs) or pages that use lazy loading. The browser tries to jump to an `id` that doesn’t exist yet. The solution here often involves making sure your JavaScript waits for the content to load before trying to activate or even set up the anchor links, or using `element.scrollIntoView()` with a delay or a promise that resolves when the element is ready.

A slightly more advanced, but still common, mistake involves elements with fixed headers. If you have a sticky or fixed navigation bar at the top of your page, when an anchor link jumps to a section, the fixed header will often overlap the content you’re trying to see. The target `id` will scroll to the top of the viewport, but your fixed header will cover the first few lines of that section. This makes it look like the anchor link is off by a bit. The fix for this usually involves adding padding to the top of your target element, or using JavaScript to calculate the scroll position and adjust it by the height of the fixed header.

Finally, let’s address the overthinking: people who get so caught up in whether anchors are inline or block, or how CSS specificity works, that they miss the obvious. They’ll write complex JS to animate scrolls when a simple `scroll-behavior: smooth;` would suffice, or they’ll meticulously craft inline styles when a CSS class would be far more maintainable.

Real-World Use: Anchors Beyond Basic Navigation

While the most common use for anchor links is creating a table of contents or navigation menu that scrolls to different sections of a single page, their utility extends much further. Understanding how they work, and that their “inlineness” is a non-issue for functionality, opens up possibilities.

Think about long articles or documentation pages. Instead of making users scroll endlessly, you can provide a sidebar navigation. Each link in the sidebar points to a specific `id` within the main content. This dramatically improves user experience, especially on mobile devices where scrolling can be cumbersome. For instance, on a long technical guide, you might have links like “Installation,” “Configuration,” “Troubleshooting,” each scrolling to its respective `id` on the page.

Another great application is within forms. Imagine a multi-step form where each step is a different section on a single page. After a user completes Step 1, you can use an anchor link to smoothly scroll them down to the beginning of Step 2. This provides a visual cue that they’ve moved forward and makes the form feel more like a guided process. For example, after successfully submitting Step 1, a link could appear: `Proceed to Step 2`, with the `id=”step-2″` on the relevant section.

Product pages can also benefit. If you have a page with extensive product details, specifications, reviews, and FAQs, an anchor link menu near the top can help users quickly find the information they need. This is particularly useful for complex products like electronics or software where users might only be interested in a specific aspect.

I used this technique extensively on a website for a line of specialized cooking appliances. The pages were packed with details about features, recipes, and technical specs. I created a sticky navigation bar with links to each major section. Users could instantly jump to “Features,” “Recipes,” “Specifications,” or “User Manual.” It significantly reduced bounce rates because people could get to the exact information they were looking for without a long scroll.

Beyond simple scrolling, anchors can be used to highlight specific content. For example, if you have a search results page and a user clicks on a result, you can scroll them to that result on the page and even apply a temporary visual highlight (using JavaScript) to make it stand out. This is a powerful way to guide the user’s eye to exactly what they searched for.

It’s also worth noting their use in conjunction with permalinks. Some content management systems (CMS) or blogging platforms automatically add `id` attributes to headings when content is published. This allows users to share a link to a specific section of an article. So, a URL might look like `example.com/blog/my-great-article#section-4`, and when that link is clicked, the browser jumps directly to the element with `id=”section-4″`. (See Also: Can Anchors In Your Shoulder Break )

The core principle remains the same: a unique `id` on a target element, and an `` tag with a matching `href`. Whether the `` tag itself is considered inline or block doesn’t affect its ability to target an `id`. It’s about the `id` being present and correctly defined on a visible element that the browser can scroll to.

Practical Tips for Flawless Anchor Links

Let’s wrap up with some practical advice. If you want your anchor links to be reliable, user-friendly, and avoid the common pitfalls, here are a few things to keep in mind. Forget the debate about whether anchors are inline; focus on implementation.

  1. Use `scroll-behavior: smooth;` in CSS. Seriously, this is the easiest win. Add `html { scroll-behavior: smooth; }` to your main stylesheet. It makes all native anchor scrolls animate smoothly, which feels infinitely better than a jarring jump. It’s supported by all modern browsers.
  2. Keep `id` attributes simple and unique. Use lowercase letters, numbers, and hyphens. Avoid spaces, special characters (except hyphens), and starting IDs with numbers if possible (though modern browsers are forgiving). Always make sure each `id` is unique on the page.
  3. Target semantic elements. Attach your `id` attributes to headings (`

    `, `

    `), `
    ` Tags, or `
    ` Elements That Clearly Define a Content Block. Don’t Try to Give an `id` to a Single Word Within a Paragraph Unless Absolutely Necessary, and Even Then, Make Sure the `id` Is on the Surrounding Block Element.
  4. consider Fixed Headers. If You Have a Fixed or Sticky Header, Your Anchor Links Might Scroll under It. To Fix This, You Can Add `padding-Top` to Your Target `id` Element Equal to the Height of Your Header. Or, If You’re Using Javascript, You Can Offset the Scroll Calculation. Some Css Solutions Exist for This Too, but They Can Be a Bit More Complex.
  5. test, Test, Test. Check Your Anchor Links Across Different Browsers (chrome, Firefox, Safari, Edge) and on Different Devices (desktop, Tablet, Mobile). What Works Perfectly on Your Development Machine Might Behave Differently Elsewhere. Use Your Browser’s Developer Tools to Inspect Elements, Check for Typos in Ids, and Make Sure the Target Element Is Where You Expect It to Be.
  6. don’t Overcomplicate with Js If Css Will Do. for the Vast Majority of Simple “scroll to Section” Needs, `scroll-Behavior: Smooth;` Is All You Need. Only Dive Into Javascript If You Need Very Specific Scroll Animations, Offsets, or Logic That Css Can’t Handle.
  7. use Descriptive `href` Values. While `` Works, `` Is Much More Readable and Understandable for Both Humans and Search Engines.
  8. by Focusing on These Practical Aspects, You Can Create Reliable and User-Friendly Anchor Links. The Question of Whether Anchors Are Inline Is a Technicality of the `` Tag Itself; the Real Work Happens in How You Structure Your Html and Apply Your Css and Javascript.

    frequently Asked Questions About Inline Anchors

    are Anchors Always Inline Elements?

    yes, the `` Tag Itself, Which Creates an Anchor Link, Is an Inline Element. This Means It Flows with the Text and Doesn’t Force a New Line. However, the Functionality of an Anchor Link Depends on the `id` Attribute of the Element It’s Linking to, Not on the Inline Nature of the `` Tag Itself.

    does the `id` Attribute Need to Be on an Inline Element?

    no, and It’s Usually Better If It’s Not. The `id` Attribute Should Be Placed on the Html Element That You Want the Anchor Link to Scroll to. This Is Typically a Block-Level Element Like a Heading (`

    `, `

    `), a `
    `, or a `
    ` That Defines a Content Area.

    why Doesn’t My Anchor Link Work?

    common Reasons Include Typos in the `href` Attribute or the `id`, Duplicate `id` Attributes on the Page, or the `id` Being Applied to an Element That Hasn’t Loaded Yet (especially with Dynamic Content). Make Sure the `id` Exactly Matches the `href` (minus the ‘#’) and Is Applied to a Valid Target Element.

    how Do I Make Anchor Links Scroll Smoothly?

    the Easiest Way Is to Add `scroll-Behavior: Smooth;` to the `html` or `body` Element in Your Css. For More Advanced Control or Older Browser Support, You Might Need to Use Javascript.

    final Thoughts

    So, to finally put it to bed: are anchors inline? The `` tag is, yes. But that’s just a technical detail about how it sits in the text flow. The real magic, and the real problems, happen with the `id` attribute you’re linking to and how you’re telling the browser to handle the scroll. Most of the time, when people struggle, it’s not because anchors aren’t inline enough, but because the `id` is missing, misspelled, duplicated, or the scroll behavior isn’t animated.

    Don’t get bogged down in semantic debates about inline vs. block for the anchor tag itself. Focus on the `id` being unique, correctly spelled, and attached to a meaningful element. And for goodness sake, use that CSS `scroll-behavior: smooth;` – it’s the single best improvement you can make to the user experience of your anchor links with almost zero effort.

    Next time you build a page with scroll links, remember this: the `` tag is just the messenger. The `id` is the destination. And `scroll-behavior: smooth;` is the chauffer making the ride pleasant. Get those right, and you’ll be golden.

Recommended Anchors
Bestseller No. 1 E-Z Ancor 25310#8 x 1-1/4' 50 Count 75lb Self-Drilling Twist-N-Lock Drywall Anchor
E-Z Ancor 25310#8 x 1-1/4" 50 Count 75lb...
SaleBestseller No. 2 KURUI 180Pcs Self Drilling Drywall Anchors with Screws Kit, Fixion Tools Metal & Heavy Duty Grip for Wall, Sheetrock, Expansion Assorted Sizes for Picture Frames, Shelves &Home Decor
KURUI 180Pcs Self Drilling Drywall Anchors with...
Bestseller No. 3 KURUI Heavy Duty Hollow Wall Anchors for Drywall Ceiling, Toggle Bolts and Wing Nut Kit, 28Pcs Metal Drywall Anchors and Screws Assortment Set, 3 Sizes Butterfly Anchors for Hanging 1/8, 3/16, 1/4
KURUI Heavy Duty Hollow Wall Anchors for Drywall...