Skip to content

Commit dd3f2e7

Browse files
Improve HTML Elements for Flow documentation (#4526)
* #4394 Better documentation for Flow HTML elements * #4394 Move standard-html to a components * #4394 fix components link not leading to HTML Elements page * #4394 fix reported Vale issues * Re-add old standard-html.adoc, but make it hidden and link it to the new page.
1 parent 27a6f72 commit dd3f2e7

File tree

7 files changed

+102
-77
lines changed

7 files changed

+102
-77
lines changed
4.13 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: HTML Elements
3+
page-title: HTML Elements | Vaadin components
4+
description: Standard HTML elements that have direct counterparts in Vaadin Flow.
5+
meta-description: Standard HTML elements that have direct counterparts in Vaadin Flow.
6+
section-nav: badge-flow
7+
---
8+
9+
10+
= Components for Standard HTML Elements
11+
12+
// tag::description[]
13+
Vaadin Flow comes with a set of components for standard HTML elements.
14+
// end::description[]
15+
Standard HTML components have an API that allows you to set most typical properties and attributes. You can also use the Element API to set any property or attribute, if the component API doesn't have an appropriate method.
16+
17+
Components that can contain other components thereby implement the [interfacename]`HtmlContainer` interface to create a hierarchical structure. The Element API allows you to create any standard HTML element using the [classname]`Element` constructor. The [classname]`ElementFactory` class contains factory methods for many standard HTML elements.
18+
19+
The module `flow-html-components` contains the following components:
20+
21+
[cols="4,2,7",options=header]
22+
|===
23+
| Component | HTML Element | Comments
24+
| `Anchor` | `a` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a[anchor element] defines a hyperlink to a resource.
25+
It can link to many kinds of targets, such as web pages, files, email addresses, or specific locations in the same page.
26+
| `Article` | `article` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/article[article element] is independent, self-contained content, such as a forum post, a blog entry, or a comment. For creating hyperlinks that navigate to a different route in your application, see <<{articles}/flow/routing/navigation#using-the-routerlink-component,RouterLink>> component.
27+
| `Aside` | `aside` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/aside[aside element] represents content that is indirectly related to the document’s main content, such as a sidebar.
28+
| `DescriptionList` | `dl` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dl[description list element] represents a description list, commonly used to implement a glossary or to display metadata (a list of key-value pairs).
29+
| `Div` | `div` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/div[div element] is a generic container for content.
30+
| `Emphasis` | `em` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/em[emphasis element] is for words that have a stressed emphasis compared to surrounding text.
31+
| `FieldSet` | `fieldset` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/fieldset[field set element] is used to organize and group related inputs and their labels in a form.
32+
| `Footer` | `footer` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/footer[footer element] represents a footer for a document or a section, often containing content such as copyright notices, contact information, or links to related documents.
33+
| `H1`, .., `H6` | `h1`, .., `h6` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements[h1 to h6 elements] represent six levels of section headings, with `h1` being the highest level and `h6` the lowest, commonly used for page or section titles.
34+
| `Header` | `header` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/header[header element] represents a container for introductory content, usually containing a logo, a search form, and a heading element.
35+
| `Hr` | `hr` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/hr[horizontal rule element] represents a thematic break between paragraph-level content, typically rendered as a horizontal rule separating sections of text.
36+
| `Html` | any | Wrapper for raw HTML content. See the <<#html-component,HTML Component>> section for more information.
37+
| `HtmlObject` | `object` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/object[object element] defines a container for an external resource, such as a web page, a picture, a media player or a resource to be handled by a plugin.
38+
| `IFrame` | `iframe` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe[iframe element] represents a nested browsing context, used for embedding another HTML page into the current one.
39+
| `Image` | `img` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/img[image element] is used to display an image within the web page.
40+
| `Input` | `input` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input[input element] defines a field where the user can enter data. For most use cases, there is a dedicated <<{articles}/components#,Vaadin component>> that provides more advanced functionality.
41+
| `ListItem` | `li` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/li[list item element] represents an item within a list. It is typically used inside an `OrderedList` or `UnorderedList`.
42+
| `Main` | `main` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/main[main element] represents the dominant content of a document’s `<body>`. Its content should be unique to the document and should not include material repeated across multiple pages, such as navigation links or footers.
43+
| `NativeButton` | `button` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button[button element] defines a clickable button. For most use cases, prefer the more advanced <<{articles}/components/button#,Vaadin Button>> component.
44+
| `NativeDetails` | `details` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details[details element] is often used to create an interactive widget that the user can open and close. For most use cases, prefer the more advanced <<{articles}/components/details#,Vaadin Details>> component.
45+
| `NativeLabel` | `label` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/label[label element] represents a caption for a form control, typically an `input`. Since most <<{articles}/components#,Vaadin field components>> provide a `setLabel(String)` method, using a `NativeLabel` is generally unnecessary.
46+
| `NativeTable` | `table` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/table[table element] represents data presented in a two-dimensional table comprised of rows and columns of cells containing data. For most use cases, prefer the more advanced Vaadin <<{articles}/components/grid#,Grid>>, <<{articles}/components/grid-pro#,Grid Pro>> or <<{articles}/components/tree-grid#,Tree Grid>>.
47+
| `NativeTableBody` | `tbody` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tbody[table body element] encapsulates a set of table rows (`NativeTableRow`).
48+
| `NativeTableCaption` | `caption` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/caption[caption element] specifies the caption (or title) of a table, providing the table an accessible description.
49+
| `NativeTableCell` | `td` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/td[table data cell element] defines a cell of a table that contains data and may be used as a child of the `NativeTableRow`.
50+
| `NativeTableFooter` | `tfoot` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tfoot[table footer element] encapsulates a set of table rows (`NativeTableRow`), typically used to provide a summary for the columns.
51+
| `NativeTableHeader` | `thead` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/thead[table head element] encapsulates a set of table rows (`NativeTableRow`), indicating that they comprise the head of a table with information about the table's columns.
52+
| `NativeTableHeaderCell` | `th` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/th[table header element] defines a header cell, which can be used inside a `NativeTableRow`, typically within a `NativeTableHeader`.
53+
| `NativeTableRow` | `tr` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/tr[table row element] defines a row of cells in a table. The row can contain either `NativeTableHeaderCell` or `NativeTableCell` elements.
54+
| `Nav` | `nav` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/nav[navigation element] defines a set of navigation links, typically used for menus, tables of contents, or indexes. Navigation is also supported by the more advanced <<{articles}/components/side-nav#,Vaadin Side Nav>> component. For menu implementations, see the <<{articles}/components/menu-bar#,Vaadin Menu Bar>> component.
55+
| `OrderedList` | `ol` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/ol[ordered list element] represents an ordered list of items (`ListItem`), typically rendered as a numbered list.
56+
| `Paragraph` | `p` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/p[paragraph element] represents a block of text, commonly known as a paragraph.
57+
| `Param` | `param` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/param[object parameter element] defines parameters for an <object> element. Usage is not recommended, as it has been deprecated in HTML.
58+
| `Pre` | `pre` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/pre[pre-formatted text element] represents pre-formatted text which is to be presented exactly as written in the HTML file, thus preserving both spaces and line breaks.
59+
| `RangeInput` | `input` | The range input element is an https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input[input element] with its `type` attribute set to `"range"`. It provides a dedicated API for slider-style inputs and is typically used to represent numeric values on a slider.
60+
| `Section` | `section` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/section[section element] represents a generic standalone section of a document. A section should typically include a heading (`H1`,...`H6`).
61+
| `Span` | `span` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/span[span element] is a generic inline container for phrasing content, which does not inherently represent anything. It is typically used to style a specific portion of text or as a placeholder for dynamic content.
62+
| `UnorderedList` | `ul` | The https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/ul[unordered list element] represents an unordered list of items (`ListItem`), typically rendered as a bulleted list.
63+
|===
64+
65+
66+
== HTML Component
67+
68+
The `Html` class in Vaadin Flow allows developers to encapsulate and manage raw HTML fragments in server-side Java applications. This component is particularly useful when you have an HTML snippet -- either as a string or loaded from a file -- that you want to insert directly into your application's layout or routes.
69+
70+
The `Html` class ensures that the HTML fragment is treated as a single unit with exactly one root element, which can be accessed and managed through the server-side code.
71+
72+
73+
=== Important Considerations
74+
75+
Regarding the `Html` Component, there are a few things to consider. First, remember that developers are responsible for sanitizing the HTML content before passing it to the `Html` component. Failure to do so may lead to cross-site scripting (XSS) vulnerabilities, as the raw HTML is sent directly to the client.
76+
77+
Once an `Html` object is created, the encapsulated HTML fragment cannot be modified. To change the content, a new `Html` instance must be created.
78+
79+
You also need to know that the `Html` component doesn't expand the HTML into a server-side DOM tree. This means that while the root element can be accessed via `getElement()`, and the inner content via `getInnerHtml()`, you can't traverse or manipulate the DOM structure on the server side.
80+
81+
Also, the HTML fragment must have exactly one root element. If the fragment contains multiple root elements, an `IllegalArgumentException` is thrown.
82+
83+
Last thing to consider is that the `Html` component doesn't support SVG elements as a root node. For SVG content, the `Svg` component should be used instead.
84+
85+
[discussion-id]`6774751B-921E-4B79-941E-830D9C3532B4`

articles/components/index.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,18 @@ include::grid-pro/index.adoc[tag=description]
461461
[.sr-only]
462462
<<{components-path-prefix}grid-pro#,See Grid Pro>>
463463

464+
ifdef::flow[]
465+
[.component-card]
466+
=== HTML Elements [badge-flow]#Flow#
467+
468+
image::{components-path-prefix}html-elements/html-elements.png["", opts=inline, role="banner"]
469+
470+
include::html-elements/index.adoc[tag=description]
471+
472+
[.sr-only]
473+
<<{components-path-prefix}html-elements#,See HTML Elements>>
474+
endif::[]
475+
464476
[.component-card]
465477
=== Icons
466478

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,8 @@
11
---
22
title: HTML Elements
3-
page-title: Using standard HTML elements in Vaadin applications
4-
description: The components for standard HTML elements included in Vaadin Flow -- and some comments about them.
5-
meta-description: Learn how to use standard HTML elements included in Vaadin Flow in your applications.
6-
order: 40
3+
section-nav: hidden
74
---
85

9-
106
= Components for Standard HTML Elements
117

12-
Vaadin Flow comes with a set of components for standard HTML elements. Standard HTML components have an API that allows you to set most typical properties and attributes. You can also use the Element API to set any property or attribute, if the component API doesn't have an appropriate method.
13-
14-
Components that can contain other components thereby implement the [interfacename]`HtmlContainer` interface to create a hierarchical structure. The Element API allows you to create any standard HTML element using the [classname]`Element` constructor. The [classname]`ElementFactory` class contains factory methods for many standard HTML elements.
15-
16-
The module `flow-html-components` contains the following components:
17-
18-
[cols="4,2,7",options=header]
19-
|===
20-
| Component | HTML Element | Comments
21-
| `Anchor` | `a` |
22-
| `Article` | `article` |
23-
| `Aside` | `aside` |
24-
| `DescriptionList` | `dl` |
25-
| `Div` | `div` |
26-
| `Emphasis` | `em` |
27-
| `FieldSet` | `fieldset` |
28-
| `Footer` | `footer` |
29-
| `H1`, .., `H6` | `h1`, .., `h6` |
30-
| `Header` | `header` |
31-
| `Hr` | `hr` |
32-
| `HtmlObject` | `object` |
33-
| `IFrame` | `iframe` |
34-
| `Image` | `img` |
35-
| `Input` | `input` |
36-
| `ListItem` | `li` |
37-
| `Main` | `main` |
38-
| `NativeButton` | `button` | `Button` class is used for `vaadin-button` Vaadin component.
39-
| `NativeDetails` | `details` | `Details` class is used for `vaadin-details` Vaadin component.
40-
| `NativeLabel` | `label` |
41-
| `NativeTable` | `table` |
42-
| `NativeTableBody` | `tbody` |
43-
| `NativeTableCaption` | `caption` |
44-
| `NativeTableCell` | `td` |
45-
| `NativeTableFooter` | `tfoot` |
46-
| `NativeTableHeader` | `thead` |
47-
| `NativeTableHeaderCell` | `th` |
48-
| `NativeTableRow` | `tr` |
49-
| `Nav` | `nav` |
50-
| `OrderedList` | `ol` |
51-
| `Paragraph` | `p` |
52-
| `Param` | `param` | Usage https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/param[not recommended].
53-
| `Pre` | `pre` |
54-
| `RangeInput` | `input` | `input` with `type="range"`
55-
| `Section` | `section` |
56-
| `Span` | `span` |
57-
| `UnorderedList` | `ul` |
58-
|===
59-
60-
61-
== HTML Component
62-
63-
The `Html` class in Vaadin Flow allows developers to encapsulate and manage raw HTML fragments in server-side Java applications. This component is particularly useful when you have an HTML snippet -- either as a string or loaded from a file -- that you want to insert directly into your application's layout or routes.
64-
65-
The `Html` class ensures that the HTML fragment is treated as a single unit with exactly one root element, which can be accessed and managed through the server-side code.
66-
67-
68-
=== Important Considerations
69-
70-
Regarding the `Html` Component, there are a few things to consider. First, remember that developers are responsible for sanitizing the HTML content before passing it to the `Html` component. Failure to do so may lead to cross-site scripting (XSS) vulnerabilities, as the raw HTML is sent directly to the client.
71-
72-
Once an `Html` object is created, the encapsulated HTML fragment cannot be modified. To change the content, a new `Html` instance must be created.
73-
74-
You also need to know that the `Html` component doesn't expand the HTML into a server-side DOM tree. This means that while the root element can be accessed via `getElement()`, and the inner content via `getInnerHtml()`, you can't traverse or manipulate the DOM structure on the server side.
75-
76-
Also, the HTML fragment must have exactly one root element. If the fragment contains multiple root elements, an `IllegalArgumentException` is thrown.
77-
78-
Last thing to consider is that the `Html` component doesn't support SVG elements as a root node. For SVG content, the `Svg` component should be used instead.
79-
80-
[discussion-id]`6774751B-921E-4B79-941E-830D9C3532B4`
8+
This article has been moved to the new <<{articles}/components/html-elements#,HTML Elements>> page.

articles/styling/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ span.warning {
226226
}
227227
----
228228

229-
See <</flow/create-ui/standard-html#, Native HTML element classes in Flow>> and <<styling-other-elements#, Applying CSS to native HTML elements>> for more information.
229+
See <</components/html-elements#, Native HTML element classes in Flow>> and <<styling-other-elements#, Applying CSS to native HTML elements>> for more information.
230230

231231

232232
=== Applying Styles with Utility Classes

articles/styling/styling-components/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ CSS class names are identifier-attributes applied to HTML elements in order to s
106106

107107
=== Style Properties Scoped to Part of the UI
108108

109-
Style property values can also be applied to any container element, such as <<{articles}/components/horizontal-layout#,Horizontal Layout>> and <<{articles}/components/vertical-layout#,Vertical Layout>> or <<{articles}/flow/create-ui/standard-html#, HTML elements>> like ``div``s, typically by applying CSS class names to them. All Vaadin components, as well as other child elements, automatically inherit style property values applied to their parent elements:
109+
Style property values can also be applied to any container element, such as <<{articles}/components/horizontal-layout#,Horizontal Layout>> and <<{articles}/components/vertical-layout#,Vertical Layout>> or <<{articles}/components/html-elements#, HTML elements>> like ``div``s, typically by applying CSS class names to them. All Vaadin components, as well as other child elements, automatically inherit style property values applied to their parent elements:
110110

111111
[.example]
112112
--

articles/styling/styling-components/styling-component-instances.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ In previous versions of Vaadin, a different feature called _theme names_ was use
9393

9494
== Applying CSS Based on Parent Element
9595

96-
CSS can also be scoped to components based on their parent elements – such as <<{articles}/components/horizontal-layout#,Horizontal Layout>> and <<{articles}/components/vertical-layout#,Vertical Layout>> or <<{articles}/flow/create-ui/standard-html#,HTML elements>> like ``div``s – in which they are placed. This is done by applying a CSS class name to the parent element, and prefixing the selector with it:
96+
CSS can also be scoped to components based on their parent elements – such as <<{articles}/components/horizontal-layout#,Horizontal Layout>> and <<{articles}/components/vertical-layout#,Vertical Layout>> or <<{articles}/components/html-elements#,HTML elements>> like ``div``s – in which they are placed. This is done by applying a CSS class name to the parent element, and prefixing the selector with it:
9797

9898
[.example]
9999
--

0 commit comments

Comments
 (0)