Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions articles/styling/styling-elements.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Styling HTML Elements
page-title: Styling HTML Elements
description: A guide to styling HTML elements in Vaadin applications.
meta-description: Learn how to style HTML elements in Vaadin applications using CSS.
order: 40
---


= Styling HTML Elements

// TODO: Link "utility classes" to article
Native HTML elements, like `<div>` and `<span>`, can be styled the way you would normally style HTML: with CSS and utility classes. CSS classnames are typically used to target specific instances of HTML elements.

Check failure on line 13 in articles/styling/styling-elements.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'classnames'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'classnames'?", "location": {"path": "articles/styling/styling-elements.adoc", "range": {"start": {"line": 13, "column": 137}}}, "severity": "ERROR"}

[.example]
--
[source,java]
----
<source-info group="Flow"></source-info>
var warningBox = new Div("Warning!");
warningBox.addClassNames("warning-message");
----

[source,tsx]
----
<source-info group="React"></source-info>
<div className="warning-message">Warning!</div>
----
--

[source,css]
----
.warning-message {
background-color: #ff8904;
}
----

// TODO: Link "utility classes" to article
Utility classes like Tailwind CSS or Lumo Utility Classes can be applied directly to HTML elements:

[.example]
--
[source,java]
----
<source-info group="Flow"></source-info>
var warningBox = new Div("Warning!");
warningBox.addClassNames("bg-orange-400 p-20");
----

[source,tsx]
----
<source-info group="React"></source-info>
<div className="bg-orange-400 p-20">Warning!</div>
----
--

<<{articles}/styling#inline-styles,Inline styles>> can also be applied to individual elements and components.

[.example]
--
[source,java]
----
<source-info group="Flow"></source-info>
var warningBox = new Div("Warning!");
warningBox.getStyles().setBackground("#ff8904");
----

[source,tsx]
----
<source-info group="React"></source-info>
<div style={{ backgroundColor: '#ff8904' }}>Warning!</div>
----
--

<<{articles}/styling/styling-components#theme-style-properties,Theme style properties>> can be used to apply theme styles to any HTML element:

[source,css]
----
.warning-message {
background-color: var(--lumo-warning-color);
}
----
Loading