Skip to main content

How to Change li Style into Font Awesome Icons


Adding Dependency

First, we add font-awesome to our page to use its icons. Take not that plugins use in this tutorial, are included in the downloadable.

Place the code below in the header section of your page.

  1. <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">

Creating the List

Next, we create the list that we are going to modify the style.

  1. <ul id="myList">
  2. <li>Apple</li>
  3. <li>Orange</li>
  4. <li>Strawberry</li>
  5. <li>Pineapple</li>
  6. </ul>

Adding CSS

Lastly, we add the CSS to change the style of our list.

  1. #myList{
  2. list-style: none;
  3. }
  4. #myList li {
  5. padding-left: 1.3em;
  6. }
  7. #myList li:before {
  8. content: "\f046";
  9. font-family: FontAwesome;
  10. display: inline-block;
  11. margin-left: -1.3em;
  12. width: 1.3em;
  13. }
  14. #listDiv{
  15. font-size: 20px;
  16. }

In the content is where you put the unicode of the font awesome that you want to substitute to the default style.

font awesome unicode

Full HTML

Here's the full HTML.

  1. <!DOCTYPE html>
  2. <meta charset="utf-8">
  3. <title>How to Change li Style into Font Awesome Icons</title>
  4. <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
  5. <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">
  6. <style type="text/css">
  7. #myList{
  8. list-style: none;
  9. }
  10. #myList li {
  11. padding-left: 1.3em;
  12. }
  13. #myList li:before {
  14. content: "\f046";
  15. font-family: FontAwesome;
  16. display: inline-block;
  17. margin-left: -1.3em;
  18. width: 1.3em;
  19. }
  20. #listDiv{
  21. font-size: 20px;
  22. }
  23. </style>
  24. </head>
  25. <div class="container">
  26. <h1 class="page-header text-center">Change li Style into Font Awesome Icons</h1>
  27. <div class="row">
  28. <div class="col-sm-4 col-sm-offset-4" id="listDiv">
  29. <h3>FRUITS</h3>
  30. <ul id="myList">
  31. <li>Apple</li>
  32. <li>Orange</li>
  33. <li>Strawberry</li>
  34. <li>Pineapple</li>
  35. </ul>
  36. </div>
  37. </div>
  38. </div>
  39. </body>
  40. </html>

That ends this tutorial. Happy Coding :)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.