Can I use CSS to add a bullet point to any element?

HtmlCssCss SelectorsHtml ListsListitem

Html Problem Overview


Pretty simple question, but I am not sure if it is possible. I want to add an image to act as a bullet in all <h1> elements. I know I can achieve this by:

<span class='bullet'></span><h1>My H1 text here</h1>

with css:

.bullet{
    background: url('bullet.png') no-repeat;
    display:inline-block;
    vertical-align: middle;
    background-size:100%;
    height:25px;
    width:25px;
    margin-right: 5px;
}

but is there an automatic way to do the same thing? I was thinking something like:

h1{
    list-style-image: url('bullet.png');
}

but that only seems to work with <ul> elements. I really don't want to have to paste the <span> element everywhere before the <h1> element. Any ideas?

Html Solutions


Solution 1 - Html

While you can use a :before pseudo-selector to add a "-" or "•" character in front of your element, it doesn't really make your element behave like a bullet point. Your element may look like a bullet point, but that's just a dirty hack, really, and should be avoided!

To make your element both (1) look like a bullet point and (2) behave like a bullet point, you should set the display, list-style-type and list-style-position attributes of that element.


EXAMPLE CODE

<h1>My H1 text here</h1>

h1 {
    display: list-item;          /* This has to be "list-item"                                               */
    list-style-type: disc;       /* See https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type     */
    list-style-position: inside; /* See https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-position */
}


THE FIDDLE

http://jsfiddle.net/L15a53cb/

Solution 2 - Html

You could do something like this:

h1:before {
    content:"• ";
}

See Fiddle :

http://jsfiddle.net/6kt8jhfo/6/

Solution 3 - Html

You can use pseudo-selector :before to add anything what you want before your tag.

h1:before {
    content: "- "
}

<h1>My H1 text here</h1>

Solution 4 - Html

Give a class name to the paragraph or any element and apply the below code (I have given class name as bullet):

.bullet::before {
content: '';
position: absolute;
bottom: 7px;
left: -10px;
width: 3px;
height: 3px;
background-color: #000;
border-radius: 50%;
}

Solution 5 - Html

Something like this should work

h1, h2, h3 {
  background: url("the image link goes here") 0 center no-repeat;
  padding-left: 15px; /* change this to fit your needs */
}

Solution 6 - Html

If you want to adjust dot size, color and position you can do this:

 .bullet:before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
    display: inline-block;
    background-color: #29cf00;
    vertical-align: middle;
}

Solution 7 - Html

list-style-type is reserved for ul only. You can use <h1 class="bullet"> with pseudo-element :before.

Solution 8 - Html

The very simple way to create a bullet using the before css is to utilize the font family ... this way there is no need to include any graphics and etc.

here is the class code:

.SomeClass:before {
  font-family: "Webdings";
   content: "=  ";

{

Solution 9 - Html

Nope, list-style and list-style-image are only for ul and ol tags you'll have to get back to your first method or make something with js

http://www.w3schools.com/css/css_list.asp http://www.w3schools.com/cssref/pr_list-style-type.asp

Solution 10 - Html

Just use <p>&bull; </p>to create a dot in front of your word

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSablefosteView Question on Stackoverflow
Solution 1 - HtmlJohn SlegersView Answer on Stackoverflow
Solution 2 - HtmlsinisakeView Answer on Stackoverflow
Solution 3 - HtmlAleshaOlegView Answer on Stackoverflow
Solution 4 - Htmlshekhar677View Answer on Stackoverflow
Solution 5 - HtmlBenView Answer on Stackoverflow
Solution 6 - HtmlVince VerhoevenView Answer on Stackoverflow
Solution 7 - HtmlmwlView Answer on Stackoverflow
Solution 8 - HtmlWho KnowsView Answer on Stackoverflow
Solution 9 - HtmlAhmadView Answer on Stackoverflow
Solution 10 - HtmlRudy PramanaView Answer on Stackoverflow