Menu Close

How to remove the space between inline or inline-block elements with CSS?

Sometimes, we want to remove the space between inline or inline-block elements with CSS.

In this article, we’ll look at how to remove the space between inline or inline-block elements with CSS.

How to remove the space between inline or inline-block elements with CSS?

To remove the space between inline or inline-block elements with CSS, we can use flexbox.

For instance, we write

<p>
  <span> Foo </span>
  <span> Bar </span>
</p>

to add a p element with 2 spans.

Then we style them by writing

p {
  display: flex;
}

span {
  width: 100px;
  font-size: 30px;
  color: white;
  text-align: center;
}

We make the p element a flex container with display: flex.

This will also remove the space between the child elements, which are the spans.

Then we style the span’s text with by changing the font size, color, and alignment.

Conclusion

To remove the space between inline or inline-block elements with CSS, we can use flexbox.

Posted in CSS