What are tag helpers, and how do they compare to HTML helpers?

ASP.NET MVC Views & Razor Basic 1–2 Yrs2–3 Yrs Conceptual 1 min read

Quick Answer

Tag helpers are server-side components that attach to HTML elements via attributes (asp-for, asp-action, asp-controller) so your markup stays HTML-like: <input asp-for="Email" />. HTML helpers are C# method calls that return markup: @Html.TextBoxFor(m => m.Email). Tag helpers are the modern default — cleaner for designers, better tooling.

Tag helpers let me write server-driven markup that still looks like HTML — <input asp-for="Email" /> generates the right name, id and validation attributes, and <a asp-action="Details" asp-route-id="5"> generates the URL from routing. HTML helpers do the same thing but as C# method calls that return strings, like @Html.TextBoxFor. Tag helpers are the default now because the markup is cleaner, front-end devs can read it, and the tooling is better. I can also write custom tag helpers by deriving from TagHelper.

  • Tag helpers: asp-for (model binding + validation attributes), asp-action/asp-controller/asp-route-* (URL generation), asp-validation-for, asp-append-version (cache busting), environment, partial, form.
  • Registered in _ViewImports.cshtml with @addTagHelper.
  • Custom tag helpers derive from TagHelper and override Process — e.g. an <email-link> element.
  • HTML helpers still work and are occasionally handy for conditional/complex generation, but tag helpers keep markup readable and diff-friendly.