×

CSS Hover

CSS Hover: CSS :hover is used to select the various elements whenever we point the mouse on these elements. We can also use this selector on all the HTML elements, instead used only on the links. To design the link for unvisited pages, a :link selector can be used. To develop the link for visited pages, a :visited selector can be used, and to design the active link, an :active selector can be used efficiently.

CSS hover was introduced in the CSS1 version. It is applied on web pages to highlight them as per user’s preference within the adequate programs of web-designing.

It contains some of the following effects:

  • It can be used to change the background color and font.
  • It can be used to change the image’s opacity.
  • It can be used for text embedding.
  • It can be used to design rollover effects on the images.
  • It can be used to swap the images.

Important: To effectively create the hover selector, we need to define it after the declaration of :visited and :link selector, if these selectors are available in the definition of the CSS.

 The hover changes the property value of elements to enable various animated modifications to the stated text/image or the reciprocal elements. Embedding of various elements of the hover within the web pages allows them to be functional and interactive.

The hover selectors are compatible with every main browser. Instead, it will be challenging to execute it on several touch devices. It is realized that the active hover operation gets stuck when using with specific non-supportive devices.

Syntax:

:hover {
css declaration;
}

Example 1: Apply hover over heading, link, and paragraph

<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align: center;
}
p:hover, h1:hover, a:hover {
background-color: pink;
}
</style>
</head>
<body>
<h1>Hover Example</h1>
<p>In this example, we are applying hover on heading, paragraph, and link</p>
<a href='https://www.javatpoint.com/css-color'>CSS Color</a>
</body>
</html>

Output:

CSS Hover

Example 2: Using CSS to change the color of the link on hover

The link color will be altered when we point the cursor over it. Its execution is easy to understand and write, if we are writing in CSS. A stylish effect will be created.

<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align:center;
}
a {
color: green;
}
a:hover {
color: lightblue;
}
a:active {
color: cyan;
}
</style>
</head>
<body>
<h1>Point the mouse on this link and see the effect of hover.</h1>
<a class= "link" href='https://www.javatpoint.com/css-color'>CSS Color</a>
</body>
</html>

Output:

CSS Hover

Example 3: Text overlay over image hover

This code of CSS shows the text over the image as mouse hover. Let’s look at this overlay image effect as mouse hover.

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<style> 
   body{ 
      text-align:center; 
   } 
* {box-sizing: border-box;} 
.container { 
  position: relative; 
  width: 50%; 
  max-width: 300px; 
} 
.image { 
  display: block; 
  width: 100%; 
  height: auto; 
} 
.overlay { 
  position: absolute;  
  bottom: 0;  
  background: rgba(255, 255, 255, 0.5);  
  width: 100%; 
  opacity: 0;  
  transition: .9s ease; 
  font-size: 25px; 
  padding: 20px; 
}
.container:hover .overlay { 
  opacity: 1.5; 
} 
</style> 
</head> 
<body> 
<h1>Image Overlay Title Effect</h1> 
<h2>Point the mouse on the following image to see the effect of hover.</h2> 
<center> 
<div class="container"> 
      <img src="Flower3.png" class="image"> 
      <div class="overlay">Beautiful flower.</div> 
</div> </center>   
</body> 
</html> 

Output:

CSS Hover

Related Topics

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

5 minutes read.

CSS Syntax

The CSS syntax contains the selector and the declaration block, which will be clearer with the following example: Selector: A CSS selector specifies the HTML tag we wish to style. A selector can be...

2 minutes read.

CSS Selector

CSS Selector: There are some selectors used in CSS, which allows us to choose the content we wish to style. Various selectors are considered as the separation of the set...

5 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

2 minutes read.

CSS Math Functions

The CSS math functions permit numerical articulations. These CSS math functions can particularly be utilized in maybe unforeseen ways, for example, inside angles and shading the functions and in the...

3 minutes read.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Specificity

CSS Specificity: If one or more conflicting rules of CSS express a similar element, a browser will pursue a few rules to examine the specific one. Specificity can be specified...

3 minutes read.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

Difference between CSS Grid and CSS Flexbox

The way that information is arranged on a website reveals a lot about you or your company. Organizational abilities are just as important as having the right materials. The design...

3 minutes read.

CSS Margin

CSS Margin: The CSS margin property is employed to describe the space throughout the elements. It clears the range throughout the element. These properties do not have a background color...

2 minutes read.