
How to change list bullet color CSS
Requirements
- Code editor
- CSS3
- HTML
Introduction
As you're designing a website, you probably wondered if you could change the color of unordered lists bullet. You might have tried several ways and nothing seems to work, but theres a light at the end of the tunnel, my friend 😂.
As I implemented here in this blog as such:
- List item one
- List item two
- List item three
Code
CSS Way
You can get more control over the styles of a list if you use:
list-style: url(bullet.png);
That will give you the ability to change color and shape of the bullet. But if you want a simple bullet with just a different color you can style like this:
ul { list-style: none; }
Then you can create your own bullet:
ul li::before { content: "•"; color: tomato; display: inline-block; width: 1rem; margin-left: -1rem; }
The ,
and
part is necessary because we need to move the bullet to the left, since the new bullet is not in the same place as the original bullet was. We create a size
and move it to the left by its own size
.
Markup and CSS Way
What makes this situation more complicated to deal with is the fact that the bullet and the text is in the same element , so by that logic you can assume that if we create another element between those, the complication can no longer be.
Markup:
<ul> <li><span>List item one</span></li> <li><span>List item two</span></li> <li><span>List item three</span></li> </ul>
CSS:
li { color: tomato; } li span { color: black; }
That simplifies everything, but is not recommended as your markup semantics gets thrown away.
Additional Resources
Related Posts
- Data fetching in React.js / Next.js2023-01-08
- The app directory in Nextjs 132023-01-07
- How to optimize a React application performance2023-01-06
- What is React's useCallback?2021-09-02
- What does the useReducer hook do2023-01-05
- How to use Debounce in Reactjs?2023-01-04
- What is React memo?2021-08-31
- What is React's useMemo2021-09-02
- What is React's Context API?2021-08-28
- React - What is Prop Drilling?2021-08-28
- React - Controlled Vs Uncontrolled2021-08-27
- What is React Hooks2021-08-25
- How to fix Deploy directory 'build' does not exist Netlify2021-01-19
- How To fix Yarn Error: EPERM: operation not permited2021-01-15
- How to make a scroll to the top button in React2021-01-16
- How to handle loading in React2021-01-17
- How to change list bullet color CSS2021-01-18