CSS Border Between List Items

CSS Border Between List Items
Code Snippet:border between list items
Author: Joshua Comeau
Published: January 19, 2024
Last Updated: January 22, 2024
Downloads: 5,375
License: MIT
Edit Code online: View on CodePen
Read More

This simple CSS code snippet helps you to draw a border between list items. It uses CSS border property to draw border bottom of li. It’s helpful to separate lists with a line.

How to Create CSS Border Between List Items

1. First of all, create unordered list of items in HTML as follows:

<ul>
  <li>
    The Long Way to a Small, Angry Planet
  </li>
  <li>
    Winter's Orbit
  </li>
  <li>
    Master of Formalities
  </li>
  <li>
    Screw The Galaxy: Hard Luck Hank
  </li>
</ul>

2. After that, style the list items and draw border using CSS border-bottom property as follows:

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  display: grid;
  place-content: center;
}

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

li {
  font-family: sans-serif;
  font-size: 1.25rem;
  padding: 16px 0;
}

li:not(:last-of-type) {
  border-bottom: 4px solid tomato;
}

That’s all! hopefully, you have successfully created CSS border between list items. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X