Text & Content Lesson 13 of 33
Styling Links and Buttons with CSS
Style links in all their states — link, visited, hover, focus and active — and turn links into good-looking, accessible buttons and navigation menus.
Links are what make the web a web. By default they're blue and underlined, and turn purple once visited. That's clear, but often doesn't match your design. In this lesson you'll learn to style links properly, including the different states a link can be in.
Link states
A link can be in several states, and each has its own selector. These special selectors with a colon are called pseudo-classes:
a:link— a normal, unvisited linka:visited— a link the user has already openeda:hover— the mouse is over the linka:focus-visible— the link was reached with the keyboard (Tab key)a:active— the moment the link is being clicked or tapped
<style>
a { font-size: 20px; font-family: Arial, sans-serif; }
a:link { color: #0f5c4d; }
a:visited { color: #6a4c93; }
a:hover { color: #b4372b; text-decoration-thickness: 3px; }
a:focus-visible { outline: 3px solid #f2b33d; outline-offset: 2px; }
a:active { color: #f2b33d; }
</style>
<p><a href="https://www.deped.gov.ph">DepEd website</a> — hover, tab to it, and click and hold.</p>
A simple, modern link style
Most sites today just set one color for links and adjust the hover:
a {
color: #0f5c4d;
text-underline-offset: 3px;
}
a:hover {
color: #127a65;
text-decoration-thickness: 2px;
}
Turning a link into a button
Links that lead to important pages ("Enroll now", "Download module") are often styled to look like buttons:
<style>
.btn {
display: inline-block;
padding: 12px 22px;
background: #0f5c4d;
color: white;
text-decoration: none;
border-radius: 10px;
font: bold 16px Arial, sans-serif;
}
.btn:hover { background: #127a65; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #f2b33d; outline-offset: 3px; }
</style>
<a class="btn" href="#">Enroll now →</a>
Why display: inline-block? Links are inline elements, and inline elements ignore top and bottom padding when arranging lines. inline-block makes the link behave like a little box, so the padding pushes properly. See the Display lesson for details.
Button variations
<style>
.btn { display: inline-block; padding: 10px 18px; border-radius: 10px; text-decoration: none; font: bold 15px Arial, sans-serif; border: 2px solid transparent; margin: 4px; cursor: pointer; }
.primary { background: #0f5c4d; color: white; }
.primary:hover { background: #127a65; }
.secondary { background: white; color: #0f5c4d; border-color: #0f5c4d; }
.secondary:hover { background: #e3f1ec; }
.danger { background: #b4372b; color: white; }
.danger:hover { background: #cf4a3c; }
</style>
<a class="btn primary" href="#">Save</a>
<a class="btn secondary" href="#">Cancel</a>
<button class="btn danger">Delete</button>
Notice the same classes work on both <a> and <button>. As you learned in HTML, use <a> when it goes to another page and <button> when it performs an action. CSS can make them look identical.
The cursor property
cursor: pointer shows the hand icon on hover. Links get it automatically; add it to other clickable things like buttons and custom cards. Other values include not-allowed (for disabled buttons), help, text and grab.
A navigation bar
Here's a horizontal menu, the kind at the top of almost every website:
<style>
.nav {
background: #0f5c4d;
padding: 8px;
border-radius: 10px;
}
.nav a {
display: inline-block;
color: white;
text-decoration: none;
padding: 8px 14px;
border-radius: 8px;
font-family: Arial, sans-serif;
}
.nav a:hover { background: rgba(255, 255, 255, 0.15); }
.nav a.active { background: #f2b33d; color: #1d2321; }
</style>
<nav class="nav">
<a class="active" href="#">Home</a>
<a href="#">Menu</a>
<a href="#">Branches</a>
<a href="#">Contact</a>
</nav>
The active class marks the page you're currently on. In a real website, each page's HTML puts class="active" on its own link. (You'll learn to put menu items neatly in a row with Flexbox later.)
Make links easy to tap
On phones, people tap with fingers, not a precise mouse. Small links placed close together lead to wrong taps. Give links in menus enough padding so each tap area is at least about 44 × 44 pixels, and leave some space between them.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04