HTML 錨標記是 HTML 中最重要的元素之一,用於在網站之間導航、從一個頁面移動到另一個頁面、點擊滑鼠開啟某種圖像或文字。它用於定義所包含的超連結的開頭和結尾。大多數情況下,搜尋引擎使用它來定義目標 URL。它內容豐富,並且與登陸頁面更相關。
這些連結在不同的場景中代表不同的意義,例如
- 帶下劃線且紅色的連結表示活動連結
- 帶下劃線且紫色的連結表示已訪問過的連結。
- 帶有下劃線和藍色的連結表示未造訪的連結。
文法:
讓我們來看看定義 的實際語法標籤。
<a href="Link_URL">Link Home</a>
登入後複製
如上所示,語法;包含主要部分連結的標籤,定義如下:
1。 href 屬性
該屬性用於定義超鏈接,其中的目標地址大家可能很熟悉。超連結可作為網頁文件和目標連結之間的連接器。
2. 名稱屬性
中的name屬性標籤用於前往頁面的特定點。
- It’s most useful for defining large pages or to define subdivisions.
- Example:Homepage So in this example we are adding #tag at the anchor name. it’s helpful to the browser to find or jump to the defined location like home. #name can be placed after the filename.
3. Target attribute
- The target attribute is used to define the destination page or the defined target page may be opened.
- It’s used as a common option that is used by target attributes to link with other pages.
- If the target attribute defines with a blank value like “target=_blank” then it will open a new tab at the target location.
4. Title Attribute
- The title attribute is one of the important attributes used to give special attention where one can easily move when they click the link.
- If the user moves the mouse pointer onto the link reference, the title text which was given into the attribute point will be shown there.
- It works like a tooltip or details where the link will navigate. This approach makes webpages or documents more user-friendly.
Working of Anchor in HTML
- There are two scenarios through which we can anchor tags like Internal link and External link.
- Internal links are those which are showing entities that are other pages of our domain, where external links are used to show web pages that don’t consider as a part of our domain.
- Let’s see how anchor tag exactly works with both links. Internal links work as a navigator between websites to show navigation menus which are useful to everyone who visits the website can easily navigate on the required menu. As discussed above in the title attribute, internal links are useful to navigate on specific content.
- Those are also used by search engine web crawlers to exactly define the pages of a website as well as for sharing authority purposes.
- External links play an important role in tag, it’s always best practice to provide exact attribution to the source. It is useful for related content, which can show us for referring website visitors.
- Sometimes other sites upload some kind of external links, which are going to point towards our website is considered as backlinks, those give permission to flow into our site which is beneficial to improve the position of our site at SERP. (Search Engine Result Page).
- One more good thing to keep our visitors on our site for a longer time, by using target=”_blank” while writing external links, which will open a new tab.
- The text we are going to use as an Ideal anchor text identifies keywords, which are more suitable to the web page.
- Working with anchor by using Absolute and Relative By using absolute URL one can see the whole description of the destination link. It contains protocol which helps to complete domain name to reach the destination.
- Relative URL used to link given web pages showing the exact position of the relative towards the position of the current page.
- Whenever internal links are written, which are showing other pages of the same site in this case we are going to write relative URLs.
Examples
Here we are going to show some examples having use of actual tag.
1. HTML code
<h4>Examples for Anchor in HTML </h4>
<a href="https://timesofindia.indiatimes.com/">Latest News </a><br><br>
<a href="HTMLcolor.html">Navigate on other File</a><br>
登入後複製
Output:
On clicking the latest news, the output is :
By clicking on the link “Navigate on other File” it will show another webpage as:
2. HTML Code
<h2>Reach to EDUCBA </h2>
<ul>
<li><a href="https://www.educba.com/">Website</a></li>
<li><a href="mailto:[email protected]">Email US</a></li>
<li><a href="tel:+123456789">Phone</a></li>
</ul>
登入後複製
Output :
The output shows some links, and that those links are in blue they are unvisited, the link showing in purple has visited the link and this is used to show the difference in links.
3. HTML Code
<h4>Image and File Demo</h4>
<p><a href="C:\Users\\Sonali\Desktop\jerry.jpeg">Image Demo</a> It will
open image</p>
<a href="./generate-zip?id=4" download="assets.zip">Download File</a>
登入後複製
Output :
While clicking on image demo it will open the image as:
While clicking on another link it will download the file as :
結論 - HTML 中的錨點
HTML 中的錨標記用於定義直接導航到目標位置的連結。它基於 hre 屬性、name 屬性、target 屬性等主要元件。 標籤用於內部和外部連結以及絕對和相對 URL。
以上是HTML 中的錨點的詳細內容。更多資訊請關注PHP中文網其他相關文章!