Home > Web Front-end > CSS Tutorial > How to Change HTML List Bullet Colors Using Only CSS?

How to Change HTML List Bullet Colors Using Only CSS?

Mary-Kate Olsen
Release: 2024-12-25 10:44:11
Original
753 people have browsed it

How to Change HTML List Bullet Colors Using Only CSS?

How to Style Bullet Colors in HTML Lists

Q: How can I change the color of the bullets in an unsorted HTML list without using images or span tags?

A: Here's an elegant solution using CSS:

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  padding-left: 1em; 
  text-indent: -.7em;
}

li::before {
  content: "• ";
  color: red; /* or whatever color you prefer */
}
Copy after login

HTML:

<ul>
  <li>Foo</li>
  <li>Bar</li>
  <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
</ul>
Copy after login

This gives you square bullets with a red color, without the use of any images or spam tags.

The above is the detailed content of How to Change HTML List Bullet Colors Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template