docs.unity3d.com
    Show / Hide Table of Contents

    Defining custom USS styles

    The first step to define a USS style is to create a new stylesheet. Stylesheets can be used to extend the Editor’s visual appearance. This can be done by adding a file named common.uss in an Editor folder in a StyleSheets/Extensions folder hierarchy. For example, the following locations are valid:

    Assets/Editor/Stylesheets/Extensions/common.uss
    Assets/Editor/MyFolder/Stylesheets/Extensions/common.uss
    Assets/Editor/MyFolder1/MyFolder2/Stylesheets/Extensions/common.uss
    

    USS files (for Unity Style Sheet) use a CSS-like syntax to describe new styles. Here is an example:

    myStyle
    {
        width:18px;
        height:18px;
        background-image: resource("Assets/Editor/icon.png");
    }
    

    In this style, we specified that we wish to use a custom icon along with size properties. USS styles also support pseudo-states, which works like pseudo-classes in CSS. Timeline markers support the following pseudo-states:

    • Collapsed: .myStyle
    • Normal: .myStyle:checked
    • Selected: .myStyle:hover:focus:checked

    USS stylesheets also support Unity's light and dark themes. Styles in files named dark.uss and light.uss will be used as an override of the style in common.uss. For example:

    • common.uss
    myStyle
    {
       width:18px;
       height:18px;
       color: rgb(125, 125, 125);
    }
    
    • dark.uss
    myStyle
    {
       color: rgb(0, 0, 0);
       background-image: resource("icon_dark.png");
    }
    
    • light.uss
    myStyle
    {
       color: rgb(255, 255, 255);
       background-image: resource("icon_light.png");
    }
    

    In the dark theme, myStyle will be resolved to:

    myStyle
    {
       width:18px;
       height:18px;
       color: rgb(0, 0, 0);
       background-image: resource("icon_dark.png");
    }
    

    and in the light theme:

    myStyle
    {
       width:18px;
       height:18px;
       color: rgb(255, 255, 255);
       background-image: resource("icon_light.png");
    }
    
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023