Html list-style-type dash
To display dashes for list items in HTML, we're need to override the default bullets with a dash of CSS styling. Start by applying list-style: none
to the list, and then content: "– "
in a ::before
pseudo-element for list items. Here, let me show you:
And the HTML part:
Voila! With this CSS, each li
element now flaunts a dash as a proud badge!
Nudging dashes: manipulation with text indentation
You're not always going to want your dashes living life on the edge (of the layout, of course). To take control of positioning, let's meet a few CSS properties:
text-indent
: This is helpful to nudge the dash.display
: When set toinline-block
, this ensures our list items are pliable to positioning tweaks.margin-left
andwidth
: A dynamic duo for precise dash placement.padding-left
: Helpful for text indentation after the dash.
Here's a sample implementation:
Crafting unique list markers: texts and images
With text characters
Feel like making your lists stand out? Replace the content property with another character;
With image bullets
Want to crank the uniqueness up to 11? Try, list-style-image
. This works with both online images and those on your machine:
Or use a base64 encoded image:
And oh, just a quick note - before styling your heart away, check for browser compatibility using Can I Use or QuirksMode. Not all browsers appreciate fine web art. 😉
Styling alternatives: square markers
If you want to make a square deal out of your list styles:
Earning karma: Community wisdom and best practices
Don't underestimate community knowledge. A solution with high votes doesn't just have the seal of approval, it's been through nerdy nitpicking and survived!
Advanced list styling techniques
Counter strike with CSS counters
For those hierarchical or nested lists that have minds of their own, CSS counters can offer a streamlined solution, handling numbering smoothly.
Speak the language of screen readers
Accessibility isn't a buzzword, it's a standard. Get acquainted with ARIA roles and attributes to ensure readable and navigable content for everyone.
Testing, not just for exam season
Cross-browser compatibility could quite literally save your sites. Test your styles across browsers and devices for a seamless look and feel.
Was this article helpful?