---
description: Hover effects
---

# Adding Hover Effects

In most software interactive elements typically show a visual change in state when they can be interacted with.&#x20;

For example, when a button is clickable, the color of the button changes when the mouse is over the button. When text is clickable, the text has an underline underneath it or it shows an underline underneath it when the mouse is over it.&#x20;

These type of interactions are sometimes called hover effects or [pseudo](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements) states.

We can add our own pseudo states to our artboard or entire document including all artboards.&#x20;

Another way to put it is that hover effects are the styles that are applied when the mouse is moved over an element.

There are currently three methods to define hover effects.

Method 1 Define a hover effect in the page stylesheet using an id, class or type selector rule.

Method 2 Define a style declaration in a code block.&#x20;

Method 3 Use a second element as a "hover element" and all it's styles to be applied on hover

After defining a style declaration you may need to have any elements reference it.&#x20;

#### Method 1 - Defining a hover effect for an element using stylesheet template

Open the Element Options panel or dialog and select the artboard.&#x20;

Click on the stylesheet template button.&#x20;

![Element Options](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0UU0-uv70QOdS9_4Y%2Fimage.png?alt=media\&token=0113fa07-cf8a-403d-b3dc-38e6421454a3)

![Stylesheet template button](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0UX2aphQ_zadsDpwk%2Fimage.png?alt=media\&token=90430294-b222-4277-8f62-67d2ee9de3ac)

In the stylesheet template add the stylesheet token and then the styles that you want to add to the artboard view.&#x20;

![Style for an element with an ID of "MyRectangle"](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0UkcXJKhGJe1LId1H%2Fimage.png?alt=media\&token=2d51aa9a-00ca-4422-b239-b190bd5df0b9)

![](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0XC6SL_ZQez060OIY%2Fimage.png?alt=media\&token=72005557-3129-4882-a77d-06801d66bb54)

A style rule or style declaration is a way to select define a style or behavior for an element or a set of elements. You select specify which elements using a [selector](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors). More information linked at the end of this page.&#x20;

#### Method 2 - Defining a hover effect class using a code block

Add a [code block](../creating-code-blocks) to the artboard.

![](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0cWU1QFpILw_UD1NZ%2Fimage.png?alt=media\&token=f9b1e38c-423c-444e-9eed-ee8a5613d80e)

In the [markup inside](../element-options/markup-inside) field add the style declarations in style tags.&#x20;

![](https://735683391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWpp_0PwLnj_AXGL2u7%2F-Lvx727NjE4MwoahonyM%2F-Lw0YtuolGRyot3o_kxb%2Fimage.png?alt=media\&token=2fd1ba9b-2794-4e37-8616-4c9e61e21dba)

When the artboard is exported and viewed in the browser the styles will be applied as you've described them.&#x20;

With the code block above we are using the global or [universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors) selector.&#x20;

Using the [hover](https://developer.mozilla.org/en-US/docs/Web/CSS/:hover) pseudo state we're saying "Apply these styles when the mouse is hovering over the selected element".

{% hint style="info" %}
Use [Web Tools](https://developer.mozilla.org/en-US/docs/Tools) to see styles you've added in the stylesheet or in code blocks
{% endhint %}

#### Declaring classes

Some style declarations specifically "select" certain elements on the page.&#x20;

With an ID selector you are saying apply these styles to the element with this ID.

```
#myElement {
    color: blue;
}
```

With a Type selector you are saying apply these styles to all of these types of elements.&#x20;

```
li {
    color: blue;
}
```

With a Class selector you are simply saying here are some styles. Don't apply them to anything with them.&#x20;

```
.buttons {
    color: blue;
}
```

Once you have classes defined you can apply them to any elements you choose.&#x20;

In the class attribute specify the name of the class.&#x20;

Before:&#x20;

```
<p>Hello world</p>
```

With a class defined:&#x20;

```
<p class="buttons">Hello world</p>
```

### Existing Classes

Once you define style rules and style declarations once you can reuse them across artboards and projects.&#x20;

The following is one way to add an underline to all hyperlinks when the mouse is  hovered over a link:&#x20;

```
<style>

/* remove underline from hyperlinks */
a {
    text-decoration: none;
}

/* remove underline from hyperlinks nested in a div */
a:hover div {
    text-decoration: underline;
}

/* add underline to hyperlinks on hover */
a:hover {
    text-decoration: underline;
}

/* add underline to hyperlinks nested in a div on hover */
a:hover div {
    text-decoration: underline;
}

</style>
```

**Method 3 - Assigning a hover element**

To assign a hover element first create an element that has all the styles you want to apply to the first element when it is hovered (video below):&#x20;

1. Create your element (say Text element)
2. Create a second text element (the Hover Element)
3. Change the styles of the Hover Element to look like how you want the first element to look when the mouse is hovered over it
4. Select the Hover Element and then select the first text element
5. Uncheck the Export option
6. In the Element Property Panel select the Hover Element from the drop down list
7. Export the page
8. You may need to remove the sizing or positioning of the Hover Element if that is not the features you want

{% embed url="https://youtu.be/Yv2jlVxo3nI" %}



{% embed url="https://developer.mozilla.org/en-US/docs/Learn/CSS" %}

{% embed url="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors" %}

{% embed url="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements" %}

{% embed url="https://developer.mozilla.org/en-US/docs/Web/CSS/:hover" %}
