Skip to content

Link-hover-color

The link-hover-color style sets the color of the link text when the mouse cursor is over the link.

Note

link-hover-color only applies to Textual action links as described in the actions guide and not to regular hyperlinks.

Syntax

link-hover-color: <color> [<percentage>];

link-hover-color accepts a <color> (with an optional transparency level defined by a <percentage>) that is used to define the color of text enclosed in Textual action links when the mouse pointer is over it.

Defaults

If not provided, a Textual action link will have link-hover-color set to white.

Example

The example below shows some links that have their colour changed when the mouse moves over it. It also shows that link-hover-color does not affect hyperlinks.

Note

The background color also changes when the mouse moves over the links because that is the default behavior. That can be customised by setting link-hover-background but we haven't done so in this example.

Note

The GIF has reduced quality to make it easier to load in the documentation. Try running the example yourself with textual run docs/examples/styles/link_hover_color.py.

from textual.app import App
from textual.widgets import Label


class LinkHoverColorApp(App):
    def compose(self):
        yield Label(
            "Visit the [link=https://textualize.io]Textualize[/link] website.",
            id="lbl1",  # (1)!
        )
        yield Label(
            "Click [@click=app.bell]here[/] for the bell sound.",
            id="lbl2",  # (2)!
        )
        yield Label(
            "You can also click [@click=app.bell]here[/] for the bell sound.",
            id="lbl3",  # (3)!
        )
        yield Label(
            "[@click=app.quit]Exit this application.[/]",
            id="lbl4",  # (4)!
        )


app = LinkHoverColorApp(css_path="link_hover_color.css")
  1. This label has an hyperlink so it won't be affected by the link-hover-color rule.
  2. This label has an "action link" that can be styled with link-hover-color.
  3. This label has an "action link" that can be styled with link-hover-color.
  4. This label has an "action link" that can be styled with link-hover-color.
#lbl1, #lbl2 {
    link-hover-color: red;  /* (1)! */
}

#lbl3 {
    link-hover-color: hsl(60,100%,50%) 50%;
}

#lbl4 {
    link-hover-color: black;
}
  1. This will only affect one of the labels because action links are the only links that this rule affects.

CSS

link-hover-color: red 70%;
link-hover-color: black;

Python

widget.styles.link_hover_color = "red 70%"
widget.styles.link_hover_color = "black"

# You can also use a `Color` object directly:
widget.styles.link_hover_color = Color(100, 30, 173)

See also