Hover
In hover state, a distinct visual cue SHOULD be available for all users. It helps to show the interactive element that the mouse is currently focused on.
NOTE:
- New to accessibility or uncertain of requirements, it will be helpful to review all sections below.
- Already familiar with requirements, skip to the “Working Example” section for sample HTML, CSS and JavaScript (when needed), along with a working demo.
- The contrast requirement of 3:1 ratio MUST be met with the adjacent background for the border and color changes (except for change in text color) on hover.
- When hover state is shown as a change in color of the text of interactive element, the contrast requirement of 4.5:1 ratio for standard text and 3:1 for large text (text that is at least 18 points or 14 points and bold) MUST be met with the adjacent color for the interactive element in hover state.
- A thick border SHOULD be present when an interactive element is hovered on to indicate the current location.
- The hover state CAN also be shown as a change in background color or text color along with the thick border.
- The hover on interactive element SHOULD NOT cause the text on the page to move around as it could be distracting for users.
Distinguishable changes shown on hover benefit majorly the below users.
- People with limited dexterity
- People with low vision
- People with color blindness
<h2>
Change background color and apply border on hover for input field and button
</h2>
<label for="email">Email</label>
<input type="text" size="20" id="email" name="searchtext"/>
<button class="hover-effect">Submit</button>
<h2>Change background color and apply border on hover for links</h2>
<ul id="mainnav">
<li class="page_item"><a href="#">Home</a></li>
<li class="page_item"><a href="#">Services</a></li>
<li class="page_item"><a href="#">About us</a></li>
<li class="page_item"><a href="#">Contact us</a></li>
</ul>
<h2>Change text color, apply border on hover</h2>
<ul id="nav">
<li class="page_item"><a href="#">Home</a></li>
<li class="page_item"><a href="#">Services</a></li>
<li class="page_item"><a href="#">About us</a></li>
<li class="page_item"><a href="#">Contact us</a></li>
</ul>
#mainnav a {
position: relative;
font-size: 1.4em;
font-weight: 800;
color: royalblue;
text-decoration: none;
padding: 2px;
}
#mainnav { list-style-type: none; }
#mainnav a { border: 1px solid transparent; }
#mainnav a:hover,
#mainnav a:active,
#mainnav a:focus {
background-color: #DCFFFF;
color: #4169e1;
border: 1px solid #000;
}
input {
margin-bottom: 4px;
border: 2px solid transparent;
}
input:hover, input:focus {
background-color: #037ee352;
border: 2px solid #000000;
color:#000000;
}
#nav { list-style-type: none; }
#nav a {
position: relative;
font-size: 1.4em;
font-weight: 800;
color: royalblue;
overflow: hidden;
background: linear-gradient(to right, midnightblue, midnightblue 50%, royalblue 50%);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 200% 100%;
background-position: 100%;
transition: background-position 275ms ease;
text-decoration: none;
padding: 2px;
border: 1px solid transparent;
}
#nav a:hover {
background-position: 0 100%;
background-color: #5de4e4!important;
border: 1px solid #000;
}
button {
background-color: #005eab;
border: 2px solid #005eab;
border-radius: 10px;
color: #fff;
display: inline-block;
line-height: 1.15;
padding: 0.25rem 1rem;
width: auto;
text-align: center;
text-decoration: none;
font-size: 1.2rem;
margin: 0 2rem 0 0;
vertical-align: middle;
}
button:hover {
background-color: #85c8ff;
cursor: pointer;
border: 2px solid #000;
color: black;
}