Styling HTML Elements
Native HTML elements, like <div> and <span>, can be styled the way you would normally style HTML: with CSS and utility classes. CSS class names are typically used to target specific instances of HTML elements.
Source code
Java
var warningBox = new Div("Warning!");
warningBox.addClassNames("warning-message");Java
tsx
tsx
Source code
CSS
.warning-message {
background-color: #ff8904;
}Utility classes like Tailwind CSS or Lumo Utility Classes can be applied directly to HTML elements:
Source code
Java
var warningBox = new Div("Warning!");
warningBox.addClassNames("bg-orange-400 p-20");Java
tsx
tsx
Inline styles can also be applied to individual elements and components.
Source code
Java
var warningBox = new Div("Warning!");
warningBox.getStyles().setBackground("#ff8904");Java
tsx
tsx
Theme style properties can be used to apply theme styles to any HTML element:
Source code
CSS
.warning-message {
background-color: var(--lumo-warning-color);
}Theme Styles for HTML Elements
By default, native HTML elements are styled only by the browser and your own CSS. The Aura and Lumo themes can also style some of them, so that they match the Vaadin components. The <table> element is the one supported so far.
To have the theme style an element, add the vaadin-themed-html class name to it. To style every supported element in a part of the UI, add the class name to an ancestor instead:
Source code
Java
var table = new Table();
table.addClassName(Constants.THEMED_HTML_CLASS_NAME);Java
tsx
tsx
In Flow, the class name is available as Constants.THEMED_HTML_CLASS_NAME in the com.vaadin.flow.server package.
To apply the theme styles across the whole application, enable the themedHtml configuration property. It adds the vaadin-themed-html class name to the page’s <body>. In a Spring Boot application, add the following to application.properties:
Source code
properties
vaadin.themedHtml=trueTo leave an element under a themed ancestor to the browser and your own CSS, add the vaadin-unthemed-html class name to that element. In Flow, this class name is available as Constants.UNTHEMED_HTML_CLASS_NAME, in the same class.
The theme styles have zero specificity, so your own CSS overrides them. For the Flow component that renders a table, see Table.
e85f0b5a-a8f2-41c5-94ed-918f122a4eb9