×

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 Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

5 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 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 Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

Radial-gradient() CSS function

Radial-gradient() CSS function It defines a CSS in-built function, which produces a smooth transition among multiple colors. It is used to set any radial-gradient that is same as a background-image. This...

4 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

How to use google fonts in CSS

Fonts: - Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in...

4 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 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 calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 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 Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 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 Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.