--- title: Underline --- {% include_relative includes/_header.html %}
Creates a series of classes to style text underlines using modern CSS.
Jump to the demos to see each in action, or jump to a specific underline class group:
In Tailwind 3, Tailwind introduced "fancy underline styles" to allow styling of text decoration underlines and you may choose to use those instead.
The main differences are these:
ems and not
px - so the apparent position of the underline is fluid with
the font size and not fixed. Essentially, if you wanted your underline to
be level with the bottom of the descender on the letter "g" - if you set
the position with pixels and change the font size at breakpoints, you'll
need to set multiple pixel values. If you use ems, one value
should see you good for all font sizes.
underline- instead of
decoration-, both of which seem sensible, at any rate they
don't clash
const { Underline } = require('@area17/a17-tailwind-plugins');
module.exports = {
...
plugins: [Underline],
theme: {
colors: {
"grey-15": "#d9d9d9",
"grey-54": "#757575",
"grey-90": "#1a1a1a",
black: "#000",
'blue-03': "#004F91"
},
underlineColor: {
primary: "#757575",
secondary: "#004F91"
},
borderColor: ApplyColorVariables(colors, {
primary: "#000",
secondary: "#d9d9d9"
}
),
textColor: ApplyColorVariables(colors, {
primary: "#1a1a1a",
secondary: "#757575",
accent: "#004F91"
}
),
backgroundColor: ApplyColorVariables(colors, {
accent: "#004F91",
}
)
}
...
};
Requires theme.textColor, theme.borderColor and/or
theme.backgroundColor configured.
A series of classes to give the underline a style:
.underline-solid {
text-decoration-line: underline;
text-decoration-style: solid;
}
.underline-dotted {
text-decoration-line: underline;
text-decoration-style: dotted;
}
.underline-double {
text-decoration-line: underline;
text-decoration-style: double;
}
.underline-dashed {
text-decoration-line: underline;
text-decoration-style: dashed;
}
.underline-wavy {
text-decoration-line: underline;
text-decoration-style: wavy;
}
A series of classes to define the underline skip behavior:
.underline-skip-none {
text-decoration-line: underline;
text-decoration-skip-ink: none;
}
.underline-skip-auto {
text-decoration-line: underline;
text-decoration-skip-ink: auto;
}
.underline-skip-all {
text-decoration-line: underline;
text-decoration-skip-ink: all;
}
Two classes to use text-decoration-thickness keywords:
.underline-thickness-auto {
text-decoration-line: underline;
text-decoration-thickness: auto;
}
.underline-thickness-from-font {
text-decoration-line: underline;
text-decoration-thickness: from-font;
}
A series of thickness classes, in a px scale from 1 to pixels:
.underline-thickness-1 {
text-decoration-line: underline;
text-decoration-thickness: 1px;
}
.underline-thickness-2 {
text-decoration-line: underline;
text-decoration-thickness: 2px;
}
...
.underline-thickness-20 {
text-decoration-line: underline;
text-decoration-thickness: 20px;
}
A series of offset classes, in a arbitrary scale of 0 to 20, where
1 - 0.05em, 2 = 0.1em and so on:
.underline-offset-0 {
ttext-decoration-line: underline;
ext-underline-offset: 0;
}
.underline-offset-1 {
text-decoration-line: underline;
text-underline-offset: 0.05em;
}
.underline-offset-2 {
text-decoration-line: underline;
text-underline-offset: 0.1em;
}
...
.underline-offset-20 {
text-decoration-line: underline;
text-underline-offset: 1em;
}
A series of negative offset classes in the same arbitrary scale of 0 to 20:
.-underline-offset-1 {
text-decoration-line: underline;
text-underline-offset: -0.05em;
}
.-underline-offset-2 {
text-decoration-line: underline;
text-underline-offset: -0.1em;
}
...
.-underline-offset-20 {
text-decoration-line: underline;
text-underline-offset: -1em;
}
And finally, a series of colour classes based on your tailwind config color
set for textColor, backgroundColor and
borderColor, for example:
.underline-text-primary {
text-decoration-line: underline;
text-decoration-color: #1a1a1a;
}
.underline-text-secondary {
text-decoration-line: underline;
text-decoration-color: #757575;
}
.underline-border-primary {
text-decoration-line: underline;
text-decoration-color: #757575;
}
.underline-border-secondary {
text-decoration-line: underline;
text-decoration-color: #f00;
}
<span class="underline-solid underline-offset-4 underline-thickness-4 underline-border-tertiary underline-skip-none lg:underline-thickness-8 focus:underline-border-secondary hover:underline-border-primary"><span>
text-decoration-style){% for style in styles %}<span class="{{ style }}">{{ style }}</span>
{% endfor %}
text-decoration-skip-ink){% for style in styles %}<span class="underline-solid {{ style }}">{{ style }}</span>
{% endfor %}
text-decoration-thickness)
{% for style in styles %}<span class="underline-solid {{ style }}">{{ style }}</span>
{% endfor %}
px){% for style in styles %}<span class="underline-solid {{ style }}">{{ style }}</span>
{% endfor %}
text-underline-offset){% for style in styles %}<span class="underline-solid {{ style }}">{{ style }}</span>
{% endfor %}
{% for style in styles %}<span class="underline-solid {{ style }}">{{ style }}</span>
{% endfor %}
text-decoration-color)
Underline colour takes its values from your Tailwind config colors. It
creates classes from theme.colors and
theme.underlineColor and also name spaced classes from
theme.textColor, theme.borderColor and/or
theme.backgroundColor.
From theme.underlineColor, using the config in this document:
{% for style in styles %}<span class="underline-solid underline-thickness-2 {{ style }}">{{ style }}</span>
{% endfor %}
From theme.colors, using the config in this document:
{% for style in styles %}<span class="underline-solid underline-thickness-2 {{ style }}">{{ style }}</span>
{% endfor %}
And finally, from theme.textColor,
theme.borderColor and/or theme.backgroundColor,
using the config in this document:
{% for style in styles %}<span class="underline-solid underline-thickness-2 {{ style }}">{{ style }}</span>
{% endfor %}