CSS Links and Buttons
Style interactive controls with clear states and accessible behavior.
Links are one of the most important parts of the web. They allow users to move from one page to another, visit external websites, download files, and access different sections of a website. Navigation menus are collections of links that help visitors find information quickly and easily.
By default, links have a basic browser style, usually blue and underlined. CSS allows developers to customize links and navigation menus to match the design of a website and improve the user experience.
Why Style Links and Navigation Menus?
Well-designed links and menus help:
- Improve website navigation
- Enhance user experience
- Create a professional appearance
- Highlight important pages
- Make websites easier to use
For example, an online store may have a navigation menu with links to products, categories, offers, and customer support pages.
Styling Basic Links
HTML links are created using the anchor element.
Example
<a href="https://www.devbrainbox.com/">Visit Website</a>CSS can change the appearance of links.
Example
a {
color: blue;
text-decoration: none;
}In this example:
- The link text becomes blue.
- The default underline is removed.
Link States
Links can have different styles depending on how users interact with them.
Unvisited Link
a:link {
color: blue;
}Styles links that have not been visited.
Visited Link
a:visited {
color: purple;
}Styles links that users have already clicked.
Hover Effect
a:hover {
color: red;
}Changes the link color when the user moves the mouse over it.
Active Link
a:active {
color: green;
}Applies styling while the link is being clicked.
These states help provide visual feedback to users.
Creating a Simple Navigation Menu
Navigation menus are often built using unordered lists.
HTML
<ul class="menu">
<li><a href="https://www.devbrainbox.com/">Home</a></li>
<li><a href="https://www.devbrainbox.com/">About</a></li>
<li><a href="https://www.devbrainbox.com/">Contact</a></li>
</ul>CSS
.menu {
list-style: none;
display: flex;
gap: 20px;
}
.menu a {
text-decoration: none;
color: black;
}This creates a simple horizontal navigation menu.
Adding Hover Effects to Menus
Hover effects make menus more interactive.
Example
.menu a:hover {
color: blue;
}When users move their mouse over a menu item, the color changes to blue.
Creating Button-Like Links
Links can also be styled as buttons.
Example
.button {
background-color: blue;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
}This is commonly used for Sign Up and Learn More buttons.
Key Takeaways
- Links Navigation is an important topic to understand.
- Start with small examples and practice one step at a time.
- Use the idea in simple projects so it becomes easier to remember.