Example
Syntax
1 | Envato Tuts+ |
Result
Linking to Sections
Anchors can also link to sections on the same page by using fragment identifiers. This takes the form of a # symbol which points to the id of an element elsewhere on the page:
1 | Jump somewhere else |
2 | |
3 | |
4 | |
5 |
This is somewhere else! |
For example, here’s a link to jump to the Learn More section below!
You can use #top or simply # to link directly to the top of the current page.
Browser Support
The tag is supported in all modern browsers. Read more on caniuse.com.
Attributes
- If the element has an href attribute, then it represents a hyperlink labeled by its contents.
- If the element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed.
The href Attribute
Content
An element allows for transparent content, but there must be no interactive content descendant, element descendant, or descendant with the tabindex attribute specified.
Accessibility
Wherever possible, make link text descriptive, rather than simply saying “click here”. For more information check out Emma Patricios’ article on creating valid and accessible links (see what I did there?).
- The element is also a type of hyperlink, but instead of being used to navigate HTML documents and files, it’s used to define a relationship between them.