Inserting visual separators with Tailwind
Tailwind allows to use arbitrary values to write selectors. Here is an example of a breadcrumb separated by the >
character:
<div class="[&>:not(:first-child):before]:content-['>_']">
<span>Clothes</span>
<span>Men's Clothes</span>
<span>Shoes</span>
<span>Current Page</span>
</div>
To reduce verbosity, you can add the variant to you tailwind config file.
// tailwind.config.js
const plugin = require("tailwindcss/plugin");
module.exports = {
plugins: [
plugin(({ addVariant }) =>
addVariant("between", "&>:not(:first-child):before")
),
],
};
And you will be able to use it like any other existing variant.
<div class="between:content-['>_']">
<span>Clothes</span>
<span>Men's Clothes</span>
<span>Shoes</span>
<span>Current Page</span>
</div>
Accessibility concern
Keep in mind that the :before
pseudo element is only used for decorative purposes so screen readers ignore them. If the content you want to display is actually meaningful, consider using JavaScript. See the WAI-ARIA explanation.