> Markdown version of [Styling Applications](https://vaadin.com/docs/v14/flow/styling/styling-applications). Section index: [llms.txt](https://vaadin.com/docs/v14/flow/llms.txt)

# Styling Applications

Learn how to apply app-specific styling across application views and application-specific components and how to use images and icons.

## <a id="prerequisites"></a>Prerequisites

You should be familiar with [Importing Style Sheets](https://vaadin.com/docs/v14/flow/styling/importing-style-sheets.md) to the different [Style Scopes](https://vaadin.com/docs/v14/flow/styling/style-scopes.md) in your application.

## <a id="styling-views-and-application-specific-components"></a>Styling Views and Application-specific Components

Your views and application-specific components are usually built by composing existing lower-level components. Styling these components is a little different from styling the internals of built-in components. See [Styling Components](https://vaadin.com/docs/v14/flow/styling/styling-components.md) for more information on styling built-in components.

### <a id="server-side-views-and-custom-components"></a>Server-Side Views and Custom Components

Server-side views and custom components (Java), extending from `Component`, are rendered in the global style scope. You can apply traditional CSS styling techniques for them.

The most common technique is to add CSS classes to the components in the view and target those classes in your style sheets.

`MyView.java`

`StylingApplications.java`

```java
@CssImport("./styles/my-view.css")
public class MyView extends VerticalLayout {
  public MyView() {
    addClassName("my-view");

    H1 heading = new H1("My View Title");
    heading.addClassName("heading");

    Paragraph text = new Paragraph("Thanks for stopping by. Not much to see here. Click the button below to go back to start.");

    Button backButton = new Button("Go Back");
    backButton.addClassName("back-button");

    add(heading, text, backButton);
  }
}
```

`styles/my-view.css`

`StylingApplications.css`

```css
.heading {
  margin-top: 0;
}

p {
  /* Assuming we are using the Lumo theme. If not, fall back to 1.2em */
  font-size: var(--lumo-font-size-l, 1.2em);
}

.back-button {
  background-color: var(--lumo-shade-90pct);
}
```

### <a id="client-side-views-templates-and-components"></a>Client-side Views, Templates and Components

Client-side view, templates, and components are usually authored using Polymer, extending `PolymerElement`. Polymer elements render their HTML template inside shadow DOM and create a new style scope.

The instructions in [Styling Polymer Templates](https://vaadin.com/docs/v14/flow/templates/polymer-templates/styling-polymer-templates.md) apply to client-side views.

If you wish to author your client-side views using some other technology (for example [LitElement](https://lit-element.polymer-project.org)), refer to the styling instructions of that technology.

## <a id="using-images"></a>Using Images

Static images, which need to be accessible by the browser, should be placed in the `/src/main/webapp/` folder. For *Spring Boot -based projects* use `/src/main/resources/META-INF/resources/`.

See [Storing and Loading Resources](https://vaadin.com/docs/v14/flow/importing-dependencies/tutorial-ways-of-importing.md) for more information about how static resources are handled.

In server-side views (Java), use the `Image` component.

**Java** — `StylingApplications.java`

```java
Image image = new Image("context://my-image.png", "Alternative text");
```

In client-side views (JavaScript), use the standard HTML `<img>` component/element. Use an absolute path for the image.

**JavaScript** — `StylingApplications.js`

```javascript
const image = document.createElement('img');
img.setAttribute('src', '/my-image.png');
img.setAttribute('alt', 'Alternative text');
```

You can also use images from CSS.

**CSS** — `StylingApplications.css`

```css
.image-bg {
  background-image: url("/my-image.png");
}
```

## <a id="using-icons"></a>Using Icons

In general, icons are not different from images, as they show a graphic on the page. For bitmap-based icons (JPG, PNG, WebP, etc.), follow the above instructions for using images.

Since icons have some additional requirements on top of images, such as the need to be able to change their size and color using CSS, they are usually created using the SVG vector format and embedded directly inside the resulting HTML, instead of being referenced via CSS `background-image: url(icon.svg)` or HTML `<img src="icon.svg">`.

Vaadin has a component specifically for showing SVG icons. In addition, Vaadin offers a large [collection of icons](https://vaadin.com/docs/v14/ds/foundation/icons/vaadin) for you to use (with both SVG and font formats).

Note, that SVG icons are considered as the best practice. Font icons have some [well documented caveats](https://cloudfour.com/thinks/seriously-dont-use-icon-fonts/), especially regarding screen reader usage.

In server-side views (Java), use the `Icon` component. There are two ways to create an icon from the Vaadin Icons collection.

The Icon component can be used in all the same places as any other component. Some components, such as Button, have API specifically for using icons.

**Java** — `StylingApplications.java`

```java
Icon edit = new Icon(VaadinIcon.EDIT);
Icon close = VaadinIcon.CLOSE.create();
```

In client-side views (JavaScript), use the `<iron-icon>` component/element.

**JavaScript** — `StylingApplications.js`

```javascript
const edit = document.createElement('iron-icon');
edit.setAttribute('icon', 'vaadin:edit');

const close = document.createElement('iron-icon');
close.setAttribute('icon', 'vaadin:close');
```

The Lumo theme has its own set of icons (see [Lumo Icons](https://vaadin.com/docs/v14/flow/styling/lumo/icons.md)), which you can also use.

**Java** — `StylingApplications.java`

```java
Icon icon = new Icon("lumo", "clock");
```

**JavaScript** — `StylingApplications.js`

```javascript
const edit = document.createElement('iron-icon');
edit.setAttribute('icon', 'lumo:clock');
```

### <a id="creating-a-custom-icon-set"></a>Creating a Custom Icon Set

If you want to create your own set of icons to use, you first need to package the SVG icons into a [`<iron-iconset-svg>`](https://github.com/PolymerElements/iron-iconset-svg) bundle. That makes them usable in client-side views and the `<iron-icon>` component/element.

For server-side views, you can create a similar Enum as `VaadinIcon` to make it easy to use your custom icon set. See the [implementation of Vaadin Icons](https://github.com/vaadin/vaadin-icons-flow/tree/master/vaadin-icons-flow/src/main/java/com/vaadin/flow/component/icon) for inspiration.

`72C8E65B-493A-4607-8793-3811BCB2EDCE`
