X
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
Learn more...
When coding a website in HTML/CSS, a fun trick to learn is to add effects when you hover over an item. The first method will teach you how to hover over text to change the CSS. There are many different tricks with the hover selector; the second method will demonstrate how to make an image appear when you hover over text.
Steps
-
1Open your HTML editor. Any code editor will work.
-
2Write your basic HTML code. Start with the basic skeleton for your page.
<!DOCTYPE html> <html> <head></head> <body> <h1>Hello!</h1> </body> </html>
Advertisement -
3Give your item a class. A class is an attribute that lets one style HTML code easily.
<h1 class="testColor">Hello!</h1>
-
4Link your style to your HTML. There are two ways to do this:
- Link a stylesheet in the head:
<head> <link rel="stylesheet" href="mystyle.css"> </head>
- Alternatively, code on that page and add the style tag to the HTML:
<!DOCTYPE html> <html> <head> <style> </style> </head> <body> <h1>Hello!</h1> </body> </html>
- Link a stylesheet in the head:
-
5Call on your class and add :hover in your CSS. The `:hover` selector must be written inside your stylesheet or within the `<style>` block in the `<head>`, not inside the HTML body. To target the class, write a period, then the class name, then `:hover`. Add the hover effects inside the curly brackets.
.testColor:hover { color: pink; } -
6Save and test your code. If working properly, the page will change when you hover over the text.
Advertisement
-
1Write a line of code that you want the hover to be connected to. Use whatever type of tag you want.
-
2
-
3Put the items you want to appear in the div tag. You might choose to copy an image URL or add your own images.
-
4
-
5
-
6Go to a browser and test your code. If working properly, the items will appear when you hover your cursor over the header.
Advertisement
Expert Q&A
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
About This Article
Thanks to all authors for creating a page that has been read 170 times.
Is this article up to date?
Advertisement












