- Mastering HTML Links: Styling, Bookmarks, Images, and Customized Behavior
- Creating HTML Links
- Using Relative URLs for Links in HTML
- Styling HTML Links
- Customizing Link Text for Hyperlinks in HTML
- How to link one page to another page in HTML
- Bookmarks in HTML
- Creating Links to Specific Sections on the Same Page in HTML
- Images as Links in HTML
- Using Images as Links in HTML
- Customizing HTML Link Behavior
- Opening Links in a New Tab or Window Using HTML
- Other HTML code examples for creating unique links
- Conclusion
- CSS Links
- Styling Links
- Example
- Example
- Text Decoration
- Example
- Background Color
- Example
- Link Buttons
- Example
- More Examples
- Example
- Example
- Example
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Link styles in html pages
- Default link style
- A second link style
- HTML Links
- HTML Links — Hyperlinks
- HTML Links — Syntax
- Example
- HTML Links — The target Attribute
- Example
- Absolute URLs vs. Relative URLs
- Example
- Absolute URLs
- Relative URLs
- HTML Links — Use an Image as a Link
- Example
- Link to an Email Address
- Example
- Button as a Link
- Example
- Link Titles
Mastering HTML Links: Styling, Bookmarks, Images, and Customized Behavior
Learn how to create different types of links in HTML, including bookmarks, image links, and customized link behavior. Improve your website’s user experience with these best practices.
- Creating HTML Links
- Styling HTML Links
- How to link one page to another page in HTML
- Bookmarks in HTML
- Images as Links in HTML
- Customizing HTML Link Behavior
- Other HTML code examples for creating unique links
- Conclusion
- How do you make a link different in HTML?
- Can I change the link of HTML?
- How do you make a link a different text?
- How do I convert a href to a different page?
HTML links are an essential component of website development. They allow users to navigate between web pages and access external resources. In this blog post, we will explore the various types of links that can be created in HTML, including how to style links, create bookmarks, use images as links, and customize link behavior . We will also cover best practices for creating links in html and common issues to avoid.
Creating HTML Links
Using Relative URLs for Links in HTML
When creating links within a website, it is best practice to use relative URLs. This allows the links to continue working even if the domain name changes. Relative URLs are also shorter and easier to read than absolute URLs.
Styling HTML Links
Links can be styled to appear differently depending on whether they have been visited, are unvisited, or are active. CSS can be used to change the appearance of links, including the color, font, and text decoration.
Customizing Link Text for Hyperlinks in HTML
Customizing link text is an important aspect of styling links. By default, links are underlined and blue, which can clash with the overall design of a website. To customize the link text, you can use CSS to change the color, font, and text decoration.
For example, to change the color of unvisited links to red and remove the underline, you would use the following CSS code:
How to link one page to another page in HTML
In this tutorial, we will learn how to connect and link two HTML pages using Notepad, using Duration: 4:28
Bookmarks in HTML
Bookmarks can be created in HTML by adding an anchor link to a specific part of a page. This allows users to quickly navigate to a specific section of a web page.
Creating Links to Specific Sections on the Same Page in HTML
To create a bookmark link to a specific section of a page, you need to give that section an ID attribute. Then, you can use the anchor tag with the href attribute set to the ID of the section.
For example, if you wanted to create a link to a section with the ID “services” on the same page, you would use the following code:
Services. Our Services We offer a variety of services to meet your needs.
Images as Links in HTML
Images can also be used as links by placing the element inside the tag. This is useful for creating visually appealing links , such as buttons or icons.
Using Images as Links in HTML
To use an image as a link, you need to wrap the element with an anchor tag and set the href attribute to the URL of the page you want to link to.
For example, to create an image link to the homepage of a website, you would use the following code:
Customizing HTML Link Behavior
Links can be customized to open in a new tab or the current tab using the target attribute. The default behavior is to open the linked page in the same tab or window.
Opening Links in a New Tab or Window Using HTML
To open a link in a new tab or window, you can add the target attribute to the anchor tag and set it to _blank .
For example, to open a link to an external website in a new tab, you would use the following code:
Other HTML code examples for creating unique links
In Html case in point, how to make a link in html code example
Conclusion
HTML links are a fundamental aspect of web development. By using the anchor tag and the href attribute, developers can create a variety of link types, including bookmarks, external links, and links to specific sections on a web page. Best practices for creating links in html include using descriptive text for the link and using relative URLs. By following these guidelines, developers can ensure that their links are functional, accessible, and user-friendly. In addition, by customizing link behavior and styling links, developers can create a more engaging and visually appealing user experience.
CSS Links
With CSS, links can be styled in many different ways.
Styling Links
Links can be styled with any CSS property (e.g. color , font-family , background , etc.).
Example
In addition, links can be styled differently depending on what state they are in.
The four links states are:
- a:link — a normal, unvisited link
- a:visited — a link the user has visited
- a:hover — a link when the user mouses over it
- a:active — a link the moment it is clicked
Example
/* unvisited link */
a:link color: red;
>
/* visited link */
a:visited color: green;
>
/* mouse over link */
a:hover color: hotpink;
>
/* selected link */
a:active color: blue;
>
When setting the style for several link states, there are some order rules:
Text Decoration
The text-decoration property is mostly used to remove underlines from links:
Example
a:visited text-decoration: none;
>
a:hover text-decoration: underline;
>
a:active text-decoration: underline;
>
Background Color
The background-color property can be used to specify a background color for links:
Example
a:link <
background-color: yellow;
>
a:visited background-color: cyan;
>
a:hover background-color: lightgreen;
>
a:active background-color: hotpink;
>
Link Buttons
This example demonstrates a more advanced example where we combine several CSS properties to display links as boxes/buttons:
Example
a:link, a:visited <
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: red;
>
More Examples
Example
This example demonstrates how to add other styles to hyperlinks:
Example
Another example of how to create link boxes/buttons:
a:link, a:visited <
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: green;
color: white;
>
Example
This example demonstrates the different types of cursors (can be useful for links):
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Link styles in html pages
This article will show you how to have different link style (colors, size, effect) in different areas in the site or on the same page.
You can download a sample html file at the end of this page.
Default link style
To set an overall style for your links in site your CSS will look like this:
a:link is where you set the link colors, background color, size, etc.
a:visited is a link color, size, padding, etc for a link that has already being clicked, visited
a:hover is link settings for the moment when mouse is over the link
A second link style
Now what about if you want to have one link color in top area of your site (header) and another link color in the bottom area of your site (footer)?! In this case you need to place the html code of the link inside a
, give that div a class name then customize that class in CSS, for example here is the html code for the » header » area:
Then the CSS for the «header» area is like this. you add the dot and class name in front of the default a:link and a:hover:
.header a:link < color:#006699; font-size:14px; text-decoration:none; padding:5px; background-color:#DDEEFF; >.header a:visited < color:#003399; font-size:14px; text-decoration:none; padding:5px; background-color:#DDEEFF; >.header a:hover
For other areas of the page do the same, place links in a div, give it a class name like header, footer, left_links, top_links, etc then inside the CSS file write that class name before the a:link.
HTML Links
Links are found in nearly all web pages. Links allow users to click their way from page to page.
HTML Links — Hyperlinks
HTML links are hyperlinks.
You can click on a link and jump to another document.
When you move the mouse over a link, the mouse arrow will turn into a little hand.
Note: A link does not have to be text. A link can be an image or any other HTML element!
HTML Links — Syntax
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
Example
This example shows how to create a link to W3Schools.com:
By default, links will appear as follows in all browsers:
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
Tip: Links can of course be styled with CSS, to get another look!
HTML Links — The target Attribute
By default, the linked page will be displayed in the current browser window. To change this, you must specify another target for the link.
The target attribute specifies where to open the linked document.
The target attribute can have one of the following values:
- _self — Default. Opens the document in the same window/tab as it was clicked
- _blank — Opens the document in a new window or tab
- _parent — Opens the document in the parent frame
- _top — Opens the document in the full body of the window
Example
Use target=»_blank» to open the linked document in a new browser window or tab:
Absolute URLs vs. Relative URLs
Both examples above are using an absolute URL (a full web address) in the href attribute.
A local link (a link to a page within the same website) is specified with a relative URL (without the «https://www» part):
Example
Absolute URLs
W3C
Relative URLs
HTML Images
CSS Tutorial
HTML Links — Use an Image as a Link
To use an image as a link, just put the tag inside the tag:
Example
Link to an Email Address
Use mailto: inside the href attribute to create a link that opens the user’s email program (to let them send a new email):
Example
Button as a Link
To use an HTML button as a link, you have to add some JavaScript code.
JavaScript allows you to specify what happens at certain events, such as a click of a button:
Example
Tip: Learn more about JavaScript in our JavaScript Tutorial.
Link Titles
The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element.