Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Using the Ionic Button Component


    Learn the changes to the Ionic button component that were introduced in version 4. Understand how to change the style and size of the button and how to quickly include an icon.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: In Ionic 3, buttons were defined using a standard button null-it then applying the ion-button directive to it. With the shift to Web components, this approach no longer worked. The Ionic button is now again defined using the ion-button.

    In addition, many of the attributes have also changed to follow Web component usage. Changing the fill and border of the button is now using the fill attribute. For buttons not in a toolbar component, this will be solid.

    If you want a clear button, set the fill to clear. This is useful for providing a large tap target for the user to interact with. If you want the background to be transparent but have a visible border, we can set this value to Outline.

    If we need to have a button that has a different width, we can also set the expand attribute to either block or full. The ion-button is an in-line block element.

    If we set the expand attribute to either block or full, this changes the element to be a block element so that the full width will be its containing element.

    The difference between the two attributes is setting the attribute to block while applying rounded corners. While setting the value to full, we'll leave the button's corner square.

    Often, you'll want to include an icon on your button. To do this, you just need to add the Ion icon component. Set its name to the value if you're using in the Ion icon library, or its source attribute if you want a custom icon.

    To define if the icon is before or after the text, use the slot attribute on the Ion icon. If you want it to appear to the left, set it to start. If you want it after, set value to end. That is the new Ionic button component.