---
title: CSS stylesheets
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Creating a new CSS stylesheet

```csharp

// Creates a new CSS stylesheet object
CssStylesheetInfo newStylesheet = new CssStylesheetInfo();

// Sets the stylesheet properties
newStylesheet.StylesheetDisplayName = "New stylesheet";
newStylesheet.StylesheetName = "NewStylesheet";
newStylesheet.StylesheetText = "CSS code";

// Saves the CSS stylesheet to the database
CssStylesheetInfoProvider.SetCssStylesheetInfo(newStylesheet);

```

[> Back to list of examples](#cssstylesheets-toc)

### Updating a CSS stylesheet

```csharp

// Gets the CSS stylesheet
CssStylesheetInfo updateStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (updateStylesheet != null)
{
    // Updates the stylesheet properties
    updateStylesheet.StylesheetDisplayName = updateStylesheet.StylesheetDisplayName.ToLower();

    // Saves the changes to the database
    CssStylesheetInfoProvider.SetCssStylesheetInfo(updateStylesheet);
}

```

[> Back to list of examples](#cssstylesheets-toc)

### Updating multiple CSS stylesheets

```csharp

// Gets all CSS stylesheets whose name starts with 'NewStylesheet'          
var stylesheets = CssStylesheetInfoProvider.GetCssStylesheets().WhereStartsWith("StylesheetName", "NewStylesheet");

// Loops through individual stylesheets
foreach (CssStylesheetInfo stylesheet in stylesheets)
{
    // Updates the stylesheet properties
    stylesheet.StylesheetDisplayName = stylesheet.StylesheetDisplayName.ToUpper();

    // Saves the changes to the database
    CssStylesheetInfoProvider.SetCssStylesheetInfo(stylesheet);
}

```

[> Back to list of examples](#cssstylesheets-toc)

### Assigning a CSS stylesheet to a site

```csharp

// Gets the CSS stylesheet
CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (stylesheet != null)
{               
    // Assigns the stylesheet to the current site
    CssStylesheetSiteInfoProvider.AddCssStylesheetToSite(stylesheet.StylesheetID, SiteContext.CurrentSiteID);
}

```

[> Back to list of examples](#cssstylesheets-toc)

### Removing a CSS stylesheet from a site

```csharp

// Gets the CSS stylesheet
CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");
if (stylesheet != null)
{
    // Gets the binding object representing the relationship between the stylesheet and the current site
    CssStylesheetSiteInfo stylesheetSite = CssStylesheetSiteInfoProvider.GetCssStylesheetSiteInfo(stylesheet.StylesheetID, SiteContext.CurrentSiteID);

    // Removes the stylesheet from the current site
    CssStylesheetSiteInfoProvider.DeleteCssStylesheetSiteInfo(stylesheetSite);
}

```

[> Back to list of examples](#cssstylesheets-toc)

### Deleting a CSS stylesheet

```csharp

// Gets the CSS stylesheet
CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("NewStylesheet");

// Deletes the CSS stylesheet
CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);

```

[> Back to list of examples](#cssstylesheets-toc)
