DEV Community

Robson Muniz
Robson Muniz

Posted on • Edited on

How to Create Amazing Buttons With Icons using HTML & CSS

In today's video I'll be showing you how to create a button with icons using HTML & CSS. This is easily done, and can be added to your own website or project/Portfolio.
I show you the full front end coding tutorial, where I create the structure of the elements in HTML and then write all of the styling and effects with CSS from scratch, step-by-step!


Markup

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Create Buttons with Icons</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>

  <button class="button">
    <span class="button__text">Like it</span>
    <span class="button__icon">
      <ion-icon name="heart-outline"></ion-icon>
    </span>
  </button>


  <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Styling

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap');

body {
    display: grid;
    height: 100vh;
    place-items: center;
    overflow: hidden;
    background: #20374e;
}
.button {
    display: flex;
    height: 50px;
    padding: 0;
    background: #2980b9;
    border: none;
    outline: none;
    border-radius: 5px;
    overflow: hidden;
    font-family: 'Roboto', sans-serif;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px;
    transition: all 160ms ease-in;
}
button:hover {
    background: #008168;
}

button:active {
    background: #006e58;
    transform: scale(.95);
}
.button__text,
.button__icon {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 24px;
    color: rgb(226, 226, 226);
}
.button__icon {
    font-size: 1.5em;
    background: rgb(0, 0, 0, 0.08);
}
Enter fullscreen mode Exit fullscreen mode

πŸ›΄ Follow me for more on:
YouTube: https://bit.ly/3oBQbc0
Facebook: https://bit.ly/3cp2S5W
Instagram[New]: https://bit.ly/3Ihh2EB

Top comments (0)