JS Days 2025 is now live – Join 5,000+ devs for the premier virtual JavaScript event. Register Now

Using Custom Icons in Your Ext JS Apps

December 11, 2013 5179 Views
Show

Do you like the glyph attribute in Ext JS 4.2 as much as I do? With glyphs, you can implement an icon that is created from a font. There are advantages to using icon fonts — they are vectors and therefore never lose quality; it’s easy to style icons without the use of Photoshop; and you make one page request to download all of the icons.

The glyph attribute is available on Ext JS buttons and panels. You can download a custom icon font from a site like: IcoMoon and implement the font in your style sheet. The value of the glyph attribute is the decimal code that maps to the unicode character which represents your icon. You add this attribute to the name of your custom font, and you’re good to go:

glyph: '115@MyIconFont',

A lot of Ext JS components extend from panel, but what if you want to implement icon fonts in other components that do not extend from Ext.panel.Panel or Ext.button.Button?

To answer this question, we can use the concepts that are actually happening under the hood:

A character is inserted before (or after) a certain DOM element. You can see an icon because this character is styled with a custom font (@font-face technique) that contains all of the icons.

Let’s try this ourselves:

  1. With your browser’s dev tools, select the DOM element in which you want to implement an icon. Ideally put a CSS class on top of it (for example: .arrow), so you can easily refer to it from your Sass.
  2. Download an icon font and map it to some character. (Let’s use the following character: > )
  3. Implement the icon font in your Sass:

    @font-face {
            font-family: 'MyIconFont';
            src: url('../resources/fonts/Nouveau.eot');
            src: url('../resources/fonts/Nouveau.eot?#iefix') format('embedded-opentype'),
            url('../resources/fonts/Nouveau.woff') format('woff'),
            url('../resources/fonts/Nouveau.ttf') format('truetype'),
            url('../resources/fonts/Nouveau.svg#Nouveau') format('svg');
            font-weight: normal;
            font-style: normal;
    }
    
  4. Alright, now comes the magic. In your Sass style sheet, write the following CSS rules:

    .arrow:before { 
            content: ">"; //the character mapped to an icon
            font-family: 'MyIconFont'; //the name of the icon font
    
            color: red; //set additional colors or dimensions...
            margin-right: 10px;
    
    }
    

The pseudo CSS selector :before will create the icon on the left side of the DOM element. The pseudo CSS selector :after will create the icon on the right side of the DOM element.

Now that you know how to use this technique, you can try it in any components, such as templates, dataviews, form fields, etc.

Want to learn more? Sencha is offering Advanced Ext JS Theming Training Live Online Jan 27-31. Take a look at the open courses located around the world or join an online training.

Recommended Articles

Guide to Estimating ROI When Switching From DIY Libraries to Full Software Development Platforms Like Ext JS

Teams started with Do It Yourself, or DIY, JavaScript tools like jQuery and Bootstrap. But those fall apart as projects scale. Scattered code, user interface…

Top Frameworks Developers Are Using for Custom Software Development in 2025

We’re seeing it more every year; teams aren’t settling for plug-and-play tools anymore. In healthcare, finance, logistics, and other data-heavy industries, there’s a clear shift.…

Meet Sencha AI Coding Companion: Your AI-Powered Assistant for Faster Ext JS Development

Building modern web applications should be exciting. But too often, developers find themselves buried in documentation, endlessly Googling framework quirks, or stuck solving the same…

Ext JS 7.9 & Rapid Ext JS V1.1 Have Arrived

The Sencha team is excited to announce the latest Ext JS version 7.9 and Rapid Ext JS 1.1 release – designed to accelerate development, enhance…

Top 10 JS Grid Customization Tips for a Better UI Experience

Grids are pretty much everywhere in web apps. Working with financial sheets, product details, or users? Then you’ve probably used a JavaScript grid. It makes…

Why Ext JS Framework is the Go-To Framework for Building Scalable and Data-Intensive Web Apps

Web apps are much more advanced now. They deal with large amounts of data and need to stay fast, even with many users. If you’re…

View More

Trusted by Top Developers: Learn how to enhance your development journey — for free

Get the latest newsletter keeping thousands of developers in the loop.

Loved by developers at