Lightning Design System (SLDS) in Visualforce pages

Salesforce Lightning Design System provides a set of CSS classes and design guidelines that allow you to create user interfaces that are consistent with the Salesforce Lightning Experience. 

You can use the Lightning Design System (SLDS) to build Visualforce pages that match the look and feel of the Salesforce mobile app. To use SLDS, it takes some tweaks in your code and a few things to remember.

Visualforce Page with SLDS

<apex:page applyHtmlTag="false" applyBodyTag="false">
    <html lang="en">
    <head>
        <title>SLDS Example in Visualforce</title>
        <apex:slds />
    </head>
    <body>
        <div class="slds-scope">
            <div class="slds-grid slds-grid_vertical">
                <div class="slds-col slds-size_1-of-2">
                    <div class="slds-box slds-box_small">
                        <p class="slds-text-heading_large">Hello, SLDS in Visualforce!</p>
                        <button class="slds-button slds-button_brand">Click Me</button>
                    </div>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <div class="slds-box slds-box_small">
                        <p class="slds-text-heading_large">Another Box</p>
                        <input type="text" class="slds-input" placeholder="Type something...">
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>

</apex:page>

In this example:

We include the SLDS stylesheet using <apex:slds />.
We create a simple layout using SLDS grid system with two columns (slds-col slds-size_1-of-2).
Each column contains a box (slds-box) with a heading (slds-text-heading_large) and either a button or an input field styled with SLDS classes.
Make sure to disable the default HTML and body tags generated by Visualforce (applyHtmlTag="false" applyBodyTag="false") when using SLDS, as SLDS provides its own HTML structure.

This example demonstrates how you can leverage SLDS classes to create visually appealing and responsive layouts in Visualforce pages that align with the Salesforce Lightning Experience design guidelines.

A few things to note when working with the Salesforce Lightning Design System in Visualforce

When using the component sample code from this site, be sure to replace all static resource paths with the Visualforce URLFOR syntax, as summarized in the FAQ.

Apex tags such as <apex:pageblock> and <apex:inputField> are not yet supported for use with the Salesforce Lightning Design System. Most likely, enabling Lightning Stylesheets will resolve your legacy code styling requests, but the Trailhead unit on Visualforce development within Lightning explains other options for styling legacy code to look like the new Lightning UI.

For best results with the Salesforce Lightning Design System, use the markup style as outlined in the component examples, and use JavaScript Remoting, Remote Objects or a similar API for data access.

To use the SVG spritemap icons, add the attributes
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
to the <html> element as documented in the Trailhead module. Do not add the attributes to individual <svg> elements as can cause a page rendering bug.

To use SVG spritemap image icons with Internet Explorer, use the svg4everybody script.

Currently, if you need to use the Salesforce header or sidebar, you can not specify the
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
on the <html> element. In this case, the SVG icons are not supported.

Links

Applying SLDS to Visualforce Pages

Using the Lightning Design System

Get the Lightning Experience in Visualforce.


Comments

Popular posts from this blog

Introduction to Salesforce Agent Script: Build Predictable AI Agents

Anti-Patterns in Salesforce Agentforce: What to Avoid When Building AI Agents

MCP vs. Traditional APIs: Choosing the Right Integration Approach