Create an HTML <a> Element Online
The HTML Hyperlink Generator creates an <a> element for a web URL, email address, or telephone number. Choose the link type and enter its destination and visible text; the preview, HTML output, and C# output update together.
Hyperlink Generator Options
The interactive generator supports these controls:
- Type creates a regular URL,
mailto:email link, ortel:telephone link. - URL, Email, or Telephone sets the link destination, while Text supplies the visible and accessible link label.
- Target controls where a URL opens. The generator omits
targetwhen_selfis selected. - Download adds the boolean
downloadattribute to a URL link. - Relationship options combine
noopener,nofollow,noreferrer,external, andhelpas space-separatedrelvalues.
Email and telephone links use only the controls relevant to those schemes. The URL-specific target, download, and relationship settings are omitted from their output.
Create an HTML <a> Element in C#
The HTML Code panel above contains the configured anchor markup. The C# Code panel below creates an equivalent element with Aspose.HTML for .NET .
The generated code follows this workflow:
- Create an
HTMLDocumentand anHTMLAnchorElementwithDocument.CreateElement(). - Set the
href, optionaltarget,rel, anddownloadattributes withElement.SetAttribute(), then assign the link text throughTextContent. - Append the anchor to the document body.
- Save the completed document as
hyperlink.htmlwithHTMLDocument.Save().
Configure the hyperlink first, then copy the updated C# code into your .NET project.
HTML Hyperlink Generator FAQ
1. Can I use a relative URL instead of a full web address?
Yes. A value such as docs/getting-started.html or ../index.html is resolved relative to the page that contains the link. Use an absolute https:// URL when the destination must remain independent of the page location.
2. What happens when someone follows a mailto or telephone link?
A mailto: link asks the device to open a configured email application, while a tel: link asks it to open a calling application. The browser does not send the email or place the call itself, and the result depends on the user’s device configuration.
3. Which relationship values should I use when a link opens a new tab?
Use noopener to prevent the opened page from accessing the original page’s browsing context. Add noreferrer when the destination should not receive referrer information; use nofollow when the publisher does not endorse the destination.
4. Why might a link with the download attribute still open in the browser?
Browsers may ignore download for cross-origin resources, and the server’s response headers can affect whether a file is displayed or downloaded. Test the generated link from the same origin and verify the resource response when download behavior is important.
5. Can I add the generated hyperlink to an existing HTML document?
Yes. Open the file with new HTMLDocument("input.html"), create and configure the anchor as shown, append it to the required element, and save the modified document to a new file.
Get Started with Aspose.HTML for .NET API
Install Aspose.HTML for .NET from NuGet with the .NET CLI:
dotnet add package Aspose.HTML
You can also use the NuGet Package Manager UI or run Install-Package Aspose.HTML in the Package Manager Console. See the
installation guide
for setup details, or request a
temporary license
to evaluate the API without evaluation limitations.
Related HTML Generators
Create other HTML structures and elements with focused generators: