docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Tab groups for code blocks

    Tab groups for code examples allow you to presentation related example content in a compact format. For example, if you have a feature that can be used in different programming languages, you can put both versions inside a tab group. The reader can pick the version they are interested in. Tab groups work in both package docs produced with the PMDT and the core Manual (with one small syntax difference).

    To create a tab group, create your code examples in the normal way (using fenced code blocks) and surround them with a div class='tab-group'>...</div> element:

        <div class="tab-group">
    
        ``` csharp
        var foo= 7.0f;
        foo = foo + 3.2f;  
        ```
    
        ``` cpp
        float foo = 7.0F;
        foo += 3.2f;
        ```
    
        ``` java
        float foo = 7;
        foo = foo + 2.4;
        ```
    
        </div>
    
        <div class="tab-group" markdown=1>
    
        ``` csharp
        var foo= 7.0f;
        foo = foo + 3.2f;  
        ```
    
        ``` cpp
        float foo = 7.0F;
        foo += 3.2f;
        ```
    
        ``` java
        float foo = 7;
        foo = foo + 2.4;
        ```
    
        </div>
    
    var foo= 7.0f;
    foo = foo + 3.2f;  
    
    float foo = 7.0F;
    foo += 3.2f;
    
    float foo = 7;
    foo = foo + 2.4;
    

    Note that there must be a blank line after the opening <div> element or the markdown processor will misinterpret the structure. In the core Unity manual, you must add a markdown=1 attribute to the <div class='tab-group'> elements.

    By default, the tab button label is the programming language derived from the language code you assigned to the fenced code block. You can also assign a different label by surrounding a code example block with a <div> element providing a title: <div class="tab-section" title="Custom title string">. (This is done in the example above.)

        <div class="tab-group">
        
        <div class="tab-section" title="C# code with long line">
    
        ``` csharp
        var foo= 7.0f;
        foo = foo + 3.2f;  
        ```
        </div>
        <div class="tab-section" markdown=1 title="Simple C++ code">
        
        This example shows C++ code:
        
        ``` cpp
        float foo = 7.0F;
        foo += 3.2f;
        ```
        </div>
        <div class="tab-section" title="Java code">
        
        ``` java
        float foo = 7;
        foo = foo + 2.4;
        ```
        </div>
        </div>
    
    var foo= 7.0f;
    foo = foo + 3.2f;  
    

    This example shows C++ code:

    float foo = 7.0F;
    foo += 3.2f;
    
    float foo = 7;
    foo = foo + 2.4;
    

    Note that you must put blank lines after each opening div tag or the markdown processor can misinterpret them as markdown text.

    When using <div class='tab-section'> elements, you can also include additional markdown content within the section.

    While you can create complex setups, like the nested tabs shown above, you are fighting against the limitations of combining html and markdown syntax. Even seemingly insignificant whitespace can derail your efforts. Even worse, syntax errors in the core Manual can break the entire manual build, not just a specific page. You can probably find better ways to spend your time. Try to keep it simple.

    Examples

    Code examples with implicit titles

    An example code block with titles derived from the language code you assigned to the fenced code block.

    var foo= 7.0f;
    foo = foo + 3.2f;  
    
    float foo = 7.0F;
    foo += 3.2f;
    
    float foo = 7;
    foo = foo + 2.4;
    

    Code examples with explicit titles

    An example code block with titles assigned in a div class='tab-section' title="Custom title" element around the code block.

    var foo= 7.0f;
    foo = foo + 3.2f; 
    // This is what code line wrap looks like:
    LongVariableType LongVariableName = LongType.Chained.WithALong.SeriesOfFunctions(foo, bar, baz).EvenMore(blat).LongType.Chained.WithALong.SeriesOfFunctions(foo, bar, baz).EvenMore(blat).LongType.Chained.WithALong.SeriesOfFunctions(foo, bar, baz).EvenMore(blat);
    
    float foo = 7.0F;
    foo += 3.2f;
    
    float foo = 7;
    foo = foo + 2.4;
    
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)