Have you ever tapped some blue text in an app, again and again, and nothing happened? Or missed an important button because it looked like plain text? Both happen when interactive text doesn't give a clear sign.
Interactive text is text you can press: links and the words on buttons. Picture a house. A door takes you to another room. A light switch turns something on in the room you are standing in. A link is a door, a button is a switch. A link takes you to another page, and a button does something on the page you are on. Both have to look usable. Both also have to give a sign when your hand (the mouse) or your attention (keyboard focus) is already on them. Keyboard focus is the element you have selected with the keyboard, the one that reacts when you press Enter.
Link or button: look at what happens when it is pressed
Pick the element by what it does, not by how it looks. In HTML, a link is the <a href="..."> tag, and href holds the address it goes to. A button is the <button> tag:
<a href="..."> link |
<button> |
|
|---|---|---|
| What happens | Goes to another page or place, the address (URL) changes | Runs an action on this page |
| On Mrs. Sri's page | "See the full cancellation rules" opens /cancellation-rules |
"2 nights" picks the number of nights, "Book the room, pay on arrival" sends the booking |
| Keyboard keys | Enter | Enter and Space |
<div onclick="..."> is neither. It is a plain box (<div>) with code that runs when it is clicked (onclick). It can't be reached with the Tab key (the key that moves from element to element) and doesn't react to Enter. So keyboard users will never get there.
The words on links and buttons also follow what they do. A button's words name its action ("Book the room, pay on arrival", not "Submit"), in weight 500 to 700, and short. A link's words name where it goes ("See the full cancellation rules", not "click here"). The reason: screen readers can read out a list of every link on the page, and ten "click here" links explain nothing.
Four states: default, hover, focus-visible, visited
Interactive text changes with its state. The default state is how it normally looks. In CSS, a state is written after the class name with a colon, for example .policy:hover. Below is the CSS for the cancellation link (.policy) and the book button (.book) on Mrs. Sri's card. In that code, text-decoration sets the underline, and outline draws the focus ring, a line around the element:
.policy { color: #15803d; text-decoration: none; } /* default */
.policy:hover,
.policy:focus-visible { color: #166534; text-decoration: underline; } /* mouse over it, or keyboard focus */
.policy:visited { color: #15803d; } /* opened before */
.book:focus-visible { outline: 3px solid #15803d; outline-offset: 2px; } /* focus ring */
:hoverapplies while the mouse pointer is over the element. Phones with touch screens have no hover, so hover must never be the only clue.:focus-visibleapplies when the element has focus and the browser judges that the focus should be visible, for example after you press Tab. A mouse click on a button usually doesn't trigger it, so the focus ring doesn't bother mouse users.:visitedis for links whose address has been opened before. For privacy, browsers only allow colour properties here (color,background-color,border-colorand the like). When JavaScript (the programming language of the browser) reads the colour, it gets the colour of an unvisited link.- The hover colour
#166534is 7.13:1 on white, the default#15803d5.02:1. Both pass the 4.5:1 minimum.
Keyboard: Tab, Enter, Space
On Mrs. Sri's card, the Tab order is: 1 night → 2 nights → 3 nights → Book the room, pay on arrival → See the full cancellation rules. That is five presses of Tab, and at every step the :focus-visible ring shows where you are. If you write outline: none with no replacement, that focus ring disappears. But WCAG requires keyboard focus to always be visible (criterion 2.4.7, level AA).
Now take a guess. Focus is on the link "See the full cancellation rules", and you press Space. What happens?
The answer: nothing happens to the link, and the browser scrolls the page down instead. The reason: Enter activates links and buttons, but Space only activates buttons. That is one more reason to use the right element. A guest who presses Space on "Book the room" expects the booking to be sent, and with a <button> it is.
Underline: when you can remove it
The underline is the best-known sign of a link. You may remove it, but only when these conditions are met:
- A link standing on its own line, like "See the full cancellation rules":
text-decoration: noneis fine, as long as the underline appears again on:hoverand:focus-visible. In the exercise, the link "See the full documentation" also stands alone, in blue#2563EB(5.17:1 on white). - A link in the middle of a sentence: if you remove the underline, the link's colour must differ by at least 3:1 from the text around it (WCAG technique G183). Green
#15803dagainst the note text#475569is only 1.51:1. Blue#2563EBagainst#1f2937text is only 2.84:1. Both are below 3:1, so inside a sentence, keep the underline.
Text that is too long: the ellipsis
On a phone, the summary bar under Mrs. Sri's card is narrow: one row with the booking summary and its total price. The summary text may be cut, but the total may not. The way to do it is the ellipsis: the "..." at the end of text that has been cut.
.bar { display: flex; gap: 8px; max-width: 260px; }
.summary {
white-space: nowrap; /* don't wrap */
overflow: hidden; /* hide what runs past the edge */
text-overflow: ellipsis; /* draw "..." at the end */
min-width: 0; /* a flex item may be narrower than its content */
}
.total { white-space: nowrap; } /* $70 always whole */
display: flex places the contents of .bar (the summary and the total) side by side in one row, with an 8px gap between them. text-overflow: ellipsis is what adds the "...", but this property only works together with white-space: nowrap and overflow: hidden. min-width: 0 is needed because .summary is a flex item (a child of a display: flex box), and without that rule it can't be narrower than its content. The result: "Terrace Room · 12 to 14 Dec..." and then "$70" in full. To cut at the second line, use display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;. Cut what can be guessed. Never cut the numbers or dates people decide on.
Input fields: at least 16px
The text in an input field (a field to fill in), "WhatsApp number" for instance, is interactive text too. If its font-size is below 16px, Safari on the iPhone zooms in on the field automatically when it is tapped. The guest then has to pinch the screen to zoom back out. Use input { font-size: 1rem; }. Don't disable page zoom through the viewport meta tag (the phone screen settings in the HTML code): people who need to enlarge text then can't.
⚠️ Lost focus, fake buttons, a stubborn ellipsis
outline: nonewith no replacement. Keyboard users lose their place. Replace it with a:focus-visiblethat has its own outline.- A div turned into a button. It can't be reached with Tab, and it doesn't react to Enter or Space. Use
<button>. - A link in a sentence with no underline. Colour alone isn't enough when its contrast with the surrounding text is below 3:1.
- An ellipsis that never appears.
text-overflow: ellipsisalone does nothing. It needswhite-space: nowrapandoverflow: hidden, and inside flex alsomin-width: 0.
TL;DR: A link (<a href>) takes you somewhere else, and a button (<button>) runs an action on this page. Enter activates both, Space only the button. Interactive text has states. :hover applies while the mouse is over it. :focus-visible applies when it is selected with the keyboard, and you should never remove its focus ring (the line around the element) with outline: none. :visited is for links opened before, and may only change colour. A link on its own line may have no underline, through text-decoration: none, as long as the underline returns on hover and focus. A link inside a sentence keeps its underline when its colour differs by less than 3:1 from the text around it. Text that is too long is cut with text-overflow: ellipsis (a "..." at the end) together with white-space: nowrap and overflow: hidden, but never cut important numbers. Text in input fields is at least 16px, so Safari on the iPhone doesn't zoom in automatically.
⚡ A link is a door, a button is a switch
Guess first: keyboard focus is on the link "See the full cancellation rules" (you selected it with Tab), and you press Space. What happens?
The link doesn't open. Space doesn't activate links. The browser scrolls the page down instead. Enter activates links and buttons, Space only buttons.
Meaning: Like a door, <a href> (a link) takes you to another page or place. Like a switch, <button> runs an action on this page. Pick the element by what happens when it is pressed, not by how it looks.
⚡ Give a sign when it is touched
Write:
.policy { color: #15803d; text-decoration: none; } /* default */
.policy:hover,
.policy:focus-visible { color: #166534; text-decoration: underline; } /* mouse over it, or keyboard focus */
.book:focus-visible { outline: 3px solid #15803d; outline-offset: 2px; } /* focus ring */
Meaning: .policy is the cancellation link, and .book is the book button. :hover applies while the mouse is over the link. :focus-visible applies when an element is selected with the keyboard. text-decoration: underline adds the underline, and outline draws a focus ring around the button. Never remove that ring with outline: none without a replacement. A link inside a sentence keeps its underline, unless its colour differs by at least 3:1 from the text around it.
⚡ An ellipsis needs three properties
Write:
.summary {
white-space: nowrap; /* don't wrap */
overflow: hidden; /* hide what runs past the edge */
text-overflow: ellipsis; /* draw "..." at the end */
}
Meaning: An ellipsis is the "..." at the end of text that has been cut. .summary is the booking summary in a narrow bar under the room card. text-overflow: ellipsis only works together with two other properties: white-space: nowrap and overflow: hidden. Cut what can be guessed, never the numbers or dates people decide on.
⚡ Inputs at least 16px
Meaning: If the font size in an input field is below 16px, Safari on the iPhone zooms in when the field is tapped. Write input { font-size: 1rem; }.